There's no certain time to treat for gnats, you just do it if the need arises. The best practice is to avoid them in the first place by not promoting conditions they thrive in or use inorganic substrates/hydro.
I've only had to deal with one infestation that was bad enough to worry about treating them and DE did the trick just fine. If you get food grade it should be safe for your plants.