How long honestly depends on climate. Properly stored, you can leave them on for a good amount of time (I'm assuming you're working with an Eduard kit). Extremes of temperature or humidity can mess with things, I guess, but I've never had a problem with removing masks when the time came.
As Hawkeye says, wait as long as possible to put them on. Not always possible, of course. I used a mask on the Mosquito I built a few months ago, and masked the canopy before attaching it, which was before priming, painting, etc. It stayed on all the way through the clear coats and weathering and was among the last things to come off toward the end of the build. Probably a good week and a half. Zero problems.
Same thing with some canopy elements of Eduard's Bf 109E-7...left the windscreen and back canopy on from before priming straight through. Zero problems. And that was probably closer to three weeks.
On the Bench: 1/32 Trumpeter P-47 | 1/32 Hasegawa Bf 109G | 1/144 Eduard MiG-21MF x2
On Deck: 1/350 HMS Dreadnought
Blog/Completed Builds: doogsmodels.com