Boy, this is a good question and it's a question I get asked a lot. For starters, it all depends on the style of beer that you are making. I'll give you a general guideline for both ale and lager home brew. Let's start with the Ale home brew.
This is such a broad category so I'll try to break it down into some general areas. If you are fermenting a beer with an average original gravity of 1.045-1.060 then you can typically leave it sit in the primary fermenter for one month max. I don't recommend leaving it for that long, actually, I don't recommend leaving it for more than three weeks, but if you forgot about your home brew and it has been sitting for one month in primary fermentation then it's most likely still fine and drinkable. If there is any hesitation then you can use your senses and smell it and taste it. NEVER dump home brew unless you absolutely know it is contaminated! I'll come and confiscate your equipment if you do! :) Seriously, use your senses and go from there. In many cases you'd want to do a primary fermentation with an ale for 7-10 days and then a secondary for a week or two. This works great for pale ales or india pale ales because you can dry hop in secondary. There are many styles that you can bottle or keg after the 10 day mark, just make sure you take hydrometer readings to ensure that fermentation is complete before bottling (Never rely on airlock activity!). Some styles include: IPA, Pale ale, Wheat beers, Ordinary bitters or anything that is low in gravity ( i.e. 1.040-1.055).
Now, if you are doing an Ale that has a gravity higher than 1.060 then you can let it age a bit longer. People who home brew Belgian Tripels or higher gravity beers like Russian Imperial Stouts or even Imperial India Pale Ales will let them primary ferment for 2-3 weeks and then secondary ferment them for another 3-6 weeks. You really should take hydrometer readings and keep records of when fermentation is done. If fermenation is done after two weeks and it's cleared up, then you can go to bottling or kegging if you wish. Or, you can rack to secondary and let it sit for two weeks. Doing higher gravity "big" beers, some people will actually bulk age them in the carboy from 1 month up to a year or more. If you do this, make sure everything is santized well and topped up to the top of the neck of the carboy.
Lagers are a lot different from Ales. For one, you have to ferment them at lower temperatures. But I'm not going to get into all of that. Right now I'm focused on how long you can primary and secondary ferment them. Since they ferment at a lower temperature it takes them longer for primary fermentation. Typically, you want to let them primary for 3 weeks. And for a secondary, that's when you can "lager" them (hold at 33 degrees for one or two months) for 1-6 months or even longer. Again, you want to make sure you are taking hydrometer readings (DO NOT RELY ON AIR LOCK ACTIVITY!) to make sure fermentation is complete. After primary fermentation is complete with the lager you want to pull it out and bring it to room temperature for 2-5 days for a diacytl rest to clean up any kind of byproducts from primary fermentation. Once that is done it's recommended to lower the temperature by 1-2 degrees each day until you hit 33 degrees and then you can lager it for as long as you wish.
And there you have it, Homebrew Junkie's general guide to primary and secondary fermentation.