Is there a way to, given a date, retrieve the season of the year? For any place on the globe?
Is this based on time zone as well as hemisphere?
Note that, In the southern hemisphere that summer is still during the warm months.
EDIT:
To clarify, I am talking about the astronomical seasons.
You can use this simple code:
private int getSeason(DateTime date) {
float value = (float)date.Month + date.Day / 100f; // <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
}
To include the seasons in the Southern Hemisphere the code can become:
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
}
The answer depends on exactly how you want to define each season. This chart at Wikipedia shows the exact day and time changes slightly from year-to-year.
A simple solution that might be "good enough" is to use four fixed dates, say: 20-March, 21-June, 22-September, and 21-December.
I don't think this is standardized. Nor is this part of the well known globalization datasets.
Someone else can rattle off the code for you quickly but from the very Wikipedia.org article you referenced we have this:
The temperate areas
We can clearly distinguish six seasons. Dates listed here are for the Northern Hemisphere:[citation needed]
* Prevernal (1 March–1 May) * Vernal (1 May–15 June) * Estival (15 June–15 August) * Serotinal (15 August–15 September) * Autumnal (15 September–1 November) * Hibernal (1 November–1 March)
You can then write a GetTemperateSeason()
function to return the enumeration above based the month ranges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With