How long in the secondary?

So there you are with your first batch in the secondary fermenter. The recipe says 2 to 4 weeks. How do you tell within that period when you’re done and it’s time to bottle?

What is the goal of this secondary, just to clear the beer, dry hopping? adding spices? If it is just to clear the beer a week or two is fine.