È possibile utilizzare questo semplice codice:
private int getSeason(DateTime date) {
float value = (float)date.Month + date.Day/100; // <month>.<day(2 digit)>
if (value < 3.21 || value >= 12.22) return 3; // Winter
if (value < 6.21) return 0; // Spring
if (value < 9.23) return 1; // Summer
return 2; // Autumn
}
Per includere le stagioni del Sud del mondo il codice può diventare:
private int getSeason(DateTime date, bool ofSouthernHemisphere) {
int hemisphereConst = (ofSouthernHemisphere ? 2 : 0);
Func<int, int> getReturn = (northern) => {
return (northern + hemisphereConst) % 4;
};
float value = (float)date.Month + date.Day/100f; // <month>.<day(2 digit)>
if (value < 3.21 || value >= 12.22) return getReturn(3); // 3: Winter
if (value < 6.21) return getReturn(0); // 0: Spring
if (value < 9.23) return getReturn(1); // 1: Summer
return getReturn(2); // 2: Autumn
}
Come si fa a definire Estate, Autunno, Inverno e Primavera? –
Hai intenzione di volere altri periodi di Branding come Natale, Pasqua, Halloween etc ?? – inspite
Chiunque cosa commentare sul downvote? Questa è una domanda reale. So che .NET ha il supporto per i fusi orari, immagino che le stagioni dovrebbero essere altrettanto abili. –