I felt like everything was at least tolerable up until I read this:
> In a particularly memorable example, a few years ago the Samoan islands wanted to be on the other side of the international date line to get the same weekends as their Australian trading partners. So on midnight Dec 29th, they changed their UTC offset from -11 to +13 UTC, skipping Dec 30th and going straight to Dec 31st.
How you could program your way out of that, and plan around that as a possibility in scheduling/calendars, is a bit mind bendy. "Turns out this day won't exist for you" is never something I'd have considered a possibility.
> "Turns out this day won't exist for you" is never something I'd have considered a possibility.
When countries switched from the Julian to the Gregorian calendar this happened everywhere. Entire counties skipping weeks in their calendars. Historical documents referring to the same event but using different dates, because they were using different calendars. Fun times. And of course not every country switched at the same time.
The Wikipedia page about this is pretty interesting [0] Some quotes from that page:
> In Russia, the Gregorian calendar was accepted after the October Revolution. On 24 January 1918 the Council of People's Commissars issued a decree that Wednesday, 31 January 1918, was to be followed by Thursday, 14 February 1918, thus dropping 13 days from the calendar.
> Catholic countries such as the Polish–Lithuanian Commonwealth adopted the "new style" (N.S.) Gregorian calendar in 1582 (switched back in 1795 after Third Partition of Poland)
And if you think that is bad, the Roman calendar that was replaced by the Julian calendar had a year consisting of 304 days and when things got too much misaligned with the seasons some extra days would be added [1]
> The system is usually said to have left the remaining 50 odd days of the year as an unorganized "winter", although Licinius Macer's lost history apparently stated the earliest Roman calendar employed intercalation instead[7][8] and Macrobius claims the 10 month calendar was allowed to shift until the summer and winter months were completely misplaced, at which time additional days belonging to no month were simply inserted into the calendar until it seemed things were restored to their proper place.
Calendars have been like that since before computer programming existed.
One of the early examples taught in high school programming classes is that of finding if a year is a leap year. Usually followed by noting how that change was introduced in most of Europe only in the late 16th century. A whole 10 days have gone missing in a bunch of countries, though everyone transitioned slightly differently. Many Eastern Orthodox countries only transitioned in 19th or 20th century, having 13 days disappear into the void.
There are also leap seconds, so your seconds can go past 59 too.
Calendars are a hard topic because they are tied to local standards so tightly. Let's not forget that not all cultures use the same "solar calendar" today either!
The best approach is to decouple timestamping from locality (eg. only ever store UTC times), and embed locale data (like DST/timezone) only if needed (if you need to show time-of-creation local times for historical data). For everything else, you should interpret for display purposes, but the arithmetic and reasoning become much simpler.
Julian dates (now's JD 2459146.6823) can help even more with that (similar to seconds-since-Unix-epoch we developers are used to, they count days-since-history-began in rational number form), but most time storage does not require stability going that far back, so just storing UTC times should work.
All you need to take the transition into account is the uptodate tz database which is available almost everywhere and in every language e.g., as zoneinfo/pytz modules in Python
> In a particularly memorable example, a few years ago the Samoan islands wanted to be on the other side of the international date line to get the same weekends as their Australian trading partners. So on midnight Dec 29th, they changed their UTC offset from -11 to +13 UTC, skipping Dec 30th and going straight to Dec 31st.
How you could program your way out of that, and plan around that as a possibility in scheduling/calendars, is a bit mind bendy. "Turns out this day won't exist for you" is never something I'd have considered a possibility.