Great question. The answer is, it depends. If you are looking to dial in your nutrition for fat adaption, a minimum of 8 weeks will yield the best results. If you are coming from a traditional sports nutrition model (i.e. high carbohydrate), your key sessions may be comprised if we make major changes too close to race day.
The ideal time to start working on your metabolic efficiency is post-race, when training volume is low, stress management can be prioritised, and time can be allocated to food preparation and the development of your new routine.
If you are well on your way and just need to fine tune things, then 4-6 weeks will work. The main thing to consider from a fuelling perspective is key sessions to trial strategies in, in order to replicate race day as closely as possible. The number one rule in racing is nothing new happens on race day.