When brewers are experimenting with new recipes, they generally have an expectation of time to complete primary fermentation based on experience with similar recipes. As you hinted, and as pkeading mentioned, gravity readings should be taken to confirm proper attenuation. After three consecutive days with no change in gravity (and assuming the gravity is close to the target FG), the beer can be racked.
Yeast metabolism is a function of temperature, so fermentations in the upper range of a yeast's allowable range will be shorter, as will fermentations with a lower starting gravities.
Generally yeast pitch rate isn't a factor, as most brewers won't deliberately underpitch or overpitch.
Secondary fermentation time is more of an art and less of a science. If during secondary, other flavors are added, such as dry hopping or oak aging, then the additive tends to dictate time in this stage. Generally, 2-3 weeks is typical for homebrewed ales, and lagers are often conditioned longer. Strong beers benefit more from increased time in secondary as well. The best way to tell if a beer is ready for bottling or kegging is to taste a sample.