A list of common misconceptions about date and time. Explanations are not exhaustive; some sections only provide counter-examples.
#Everybody uses the same calendar
Not all countries have adopted the Gregorian calendar at the same time. France, Spain, Italy and a few other countries adopted the new calendar on 15 October 1582. The British Empire changed in September 1752. Russia didn't switch until 1918. Greece was the last European country to make the change in 1923. According to Wikipedia, the last country to adopt the Gregorian calendar was Saudi Arabia in 2016.
Some cultures use different calendars based on lunar rather than solar cycles, or some combination of lunar and solar.
#1 year = 12 months
Some calendars use leap months, so a year can have 13 months. In the .NET BCL, DateTimeFormat.GetMonthName accepts a value between 1 and 13. This accommodates calendar systems that have leap months, such as those implemented by the HebrewCalendar and EastAsianLunisolarCalendar classes. For instance, the Hebrew calendar has Adar as its 6th month in a common year, which becomes Adar 1 and Adar 2 (months 6 and 7) in a Hebrew leap year.
The Ethiopian calendar has 13 months.
The Baháʼí calendar (also known as the Wondrous calendar) has 19 months and 4-5 intercalary days (which are not part of any of the 19 months).
#1 year = 365 days
Leap years have 366 days. If you are a programmer, check this post to protect your code against common errors with leap years.
#1 year = 365 or 366 days
When countries switched calendars historically, years could be shorter than usual. For example, when Great Britain changed its calendar in 1752, several days were removed from September.
Shell
TZ=BST cal 09 1752
September 1752
Su Mo Tu We Th Fr Sa
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Another example is Samoa which changed its time zone in 2011. In that year, Friday 30th December did not exist. As 2011 is not a leap year, there are only 364 days in the year. (TimeZoneInfo.FindSystemTimeZoneById("Pacific/Apia").IsInvalidTime(new DateTime(2011, 12, 30)))
The Hebrew calendar is lunar. Since lunar months are shorter than solar months, an extra month is added every few years. This results in some years having fewer than 365 days, and others having up to 385 days.
#Days are consecutive
As shown in the 1752 BST calendar, dates jump from September 2nd to September 14th.
September 1752
Su Mo Tu We Th Fr Sa
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
This happens whenever a country changes its calendar.
#Leap years are every 4 years
A year is a leap year if divisible by 4, except years divisible by 100, which are not leap years unless also divisible by 400.
- 1900 is not a leap year
- 2000 is a leap year
- 2020 is a leap year
#Anybody can implement leap years correctly
Microsoft Excel incorrectly assumes that the year 1900 is a leap year, and the reason for this bug is well explained in the documentation.
#GMT is the same as UTC
Coordinated Universal Time (UTC) is an international time scale recommended by the International Bureau of Weights and Measures (BIPM) as the legal basis for time.
Greenwich Mean Time (GMT) is a time zone, which is the mean solar time at the Royal Observatory in Greenwich, London. It corresponds to UT1, the solar time at 0° longitude.
The difference between UTC and GMT is only fractions of a second, so they are treated as equivalent for everyday use. However, the distinction matters for scientific purposes.
#Time zone offsets are always integer numbers of hours
Many time zones are not integer numbers of hours. For example, Newfoundland Daylight Time is UTC-2:30. Australian Central Western Standard Time is UTC+8:45.
#Time zone offsets are always integer numbers of minutes
There are historical examples where offsets included seconds:
Zone Asia/Kabul 4:36:48 LMT 1890
Zone Asia/Yerevan 2:58:00 LMT 1924 May 2
Zone Asia/Baku 3:19:24 LMT 1924 May 2
Zone America/Boise -7:44:49 LMT 1883 Nov 18 12:15:11
Zone Europe/Andorra 0:06:04 LMT 1901
#Time zone offsets are between -12 hours and +12 hours
Line Islands Time is UTC+14:00
#Past data never changed
Time zone data can be incorrect and later corrected, meaning historical timestamps can change. An example is Asia/Shanghai: https://stackoverflow.com/a/6841479/2996339. You can download the tz data from here and search for "Changes to past timestamps" in the NEWS file to get more examples.
#Days start at midnight
Historically, the astronomical day started at noon, a convention used until between 1920 and 1930. This allowed astronomers to record observations made on either side of midnight under the same date.
In the rabbinic Hebrew calendar, a day runs from sunset (the start of "the evening") to the next sunset (source)
#Midnight is a valid time
In Chile, daylight saving time starts at midnight, making midnight an invalid time on that day.
2019-09-07 23:59:59
2019-09-08 01:00:00
#Holidays span an integer number of whole days
In the Jewish calendar, the day begins at nightfall. So holidays listed as "Wednesday" on most calendars actually start on Tuesday night and end Wednesday night.
#DateTime + Time zone represent a single point in time
Daylight saving time can shift the clock backward, so it can represent two different moments.
#The same month has the same number of days in it everywhere
In Sweden, February 30th 1712 is valid. This date is only valid in Sweden.
#1 minute = 60 seconds
Earth's rotation period varies over time due to climatic and geological events. The variation typically accumulates to about a second every couple of years. When the difference from atomic time grows too large, a leap second is inserted as a correction, ensuring the difference never exceeds 0.9 seconds. For instance, June 30th, 2012 11:59:60 PM is a valid time.
Before Windows Server 2016, the Microsoft Time Service was not aware of leap seconds but relied on the external time service to take care of this. Windows is now aware of leap seconds.
#Days are 24 hours long
Japan observed daylight saving time from 1948 to 1951 using a strategy different from other countries: they added an extra hour at the end of the day:
Saturday 23:58
Saturday 23:59
Saturday 24:00 (no change of date)
Saturday 24:01
...
Saturday 24:58
Saturday 24:59
Sunday 00:00
Sunday 00:01
#Days are 24 hours long (bis)
A sidereal day lasts 23 hours, 56 minutes, and 4.0905 seconds. This is the time Earth takes to rotate 360 degrees relative to the stars, roughly 4 minutes shorter than the 24-hour solar day.
#A stopped clock is right twice a day
It can be right 3 times a day (when clocks go back) or only once (when clocks go forward) because of DST transitions.
#Time zone = offset
A time zone is more than just an offset. It has a name and defines how to convert a UTC date to a local civil date. This includes the calendar system, a base UTC offset, and rules for when the offset changes (such as daylight saving time). Time zones are associated with geographic regions.
Note that abbreviations like "PST" or "EST" are not time zones; they represent only half of a time zone, applying only for part of the year. Some abbreviations are also ambiguous: BST stands for British Summer Time, British Standard Time (used between 1968 and 1971), and Bangladesh Standard Time. Use IANA time zone names (e.g. Europe/London, Asia/Dhaka) to avoid such ambiguity.
#A country has 1 timezone
A country can have multiple time zones. For instance, France has 12 (13 including its claim in Antarctica) time zones spanning from UTC-11 to UTC+12.
You can find the list of time zones per country on Wikipedia.
#Daylight savings time is always -1 or +1 hour
Daylight saving time for Australia/Lord_Howe is 30 minutes. In Antarctica/Troll, the offset is 2 hours.
#Daylight savings time happens at the same time in every time zone
In Chile, daylight saving time starts at midnight. In America/Toronto, it starts at 2 am.
In Europe/Paris, daylight saving time starts the last Sunday of March. In America/Toronto, daylight saving time starts the second Sunday of March.
#All time zones in a country observe Daylight savings time
In Canada, most time zones observe daylight saving time, but Yukon (America/Creston) does not.
#Weeks start on Monday
In Israel, the week starts on Sunday.
#Weekend = Saturday and Sunday
Many countries use different rules for workweek and weekend. Here are a few examples:
- Canada: Saturday-Sunday
- Israel: Friday–Saturday
- Iran: Friday
- Nepal: Saturday
#Months are 28-31 days long
From this Stack Exchange answer and this Wikipedia page, months could be 32 days long in the Julian calendar.
Of course, the previous example with BST on September 1752 is also valid.
#Years start on January 1st
In Great Britain, before 1752, the legal years started on 25 March. Thus, for example, 24 March 1707 was immediately followed by 25 March 1708, while the day following 31 December 1708 was 1 January 1708.
In the Ethiopian calendar, years start on 11 or 12 September.
For other calendars, you can check this Wikipedia page: New Year's Day and New Year.
#There is a year 0
In the Anno Domini (AD) system, which is used to number years in the Gregorian calendar, the year 1 BC is followed directly by year AD 1. So, there is no year 0.
#Changes in time zones occur with long notice periods
Argentina gave 11 days of notice of its decision to cancel daylight saving time for 2009/2010.
In 2011, Turkey gave a two weeks notice that it was delaying the DST transition.
In 2013, Morocco gave less than a day's notice that they were changing their time zone rules.
In 2022, Chile gave a 1-month notice that it was changing its time zone rules. For companies using monthly updates, this can be tricky to implement (Interim guidance on 2022 time zone updates for Chile).
In 2023, the chief of the Antarctic research base Vostok gave less than a day's notice that they were changing their time zone rules: https://mm.icann.org/pipermail/tz/2023-December/033317.html
#The time zone for a region is well-defined
It can be difficult to determine which time zone is currently in use. For instance, in 2023, Lebanon made a last-minute announcement postponing DST. The Olson database complied. Then, there was a dispute if it happened, and parts of the government reversed it. The country had two time zones concurrently, depending on who you asked. This led to absurd statements such as Banque du Liban adheres to both timings!
#DateTime.UtcNow increases monotonically
You can change the system time manually or via an NTP server. So, DateTime.UtcNow <= DateTime.UtcNow can be false if the system time moves backward between the two calls.
#If you display a datetime, you'll get the same year as the one stored in the DateTime object.
Many date libraries support format strings for displaying dates, and some distinguish between the calendar year (e.g. yyyy) and the ISO week year (e.g. YYYY). These can differ, so the displayed year may not match the stored value. For example, 2022-01-02 falls in week 52 of the year 2021. Modern libraries use clearly distinct format characters to reduce such confusion.
#Computing the number of days between 2 dates is simple
Time zones and calendar changes mean that computing the number of days between two dates may require additional logic. How do you handle missing days, such as those in September 1752 (BST) or December 30, 2011 (Pacific/Apia)? This may explain why the MS SQL Server DATETIME type does not support dates before 1753-01-01. SQL Server was originally developed by a team in Great Britain, so they likely chose to avoid the complexity of the 1752 calendar change. Use DATETIME2 if you need to store dates before 1753.
#32 bits is enough to store anything
With a signed 32-bit integer, Unix timestamps can only represent dates until year 2038. Switch to 64-bit integers to avoid this limitation.
.NET had a performance issue every ~29 days in some benchmarks. The root cause was that the thread-pool used Environment.TickCount, a signed 32-bit value.
#Storing dates in UTC prevents all issues
If you want to schedule a meeting at 10 AM in New York next year, do not convert to UTC and store it. DST rules may change before the meeting, making the stored time incorrect.
#Synchronizing time between machines is easy
Time synchronization is critical in distributed systems. The Network Time Protocol (NTP) synchronizes clocks across machines. Several factors make accurate synchronization difficult:
- The NTP server may not be accurate
- The network may be congested
- The network may be asymmetric (different number of hops for the request and response)
- The machine's clock may drift too quickly
These posts explain how Windows uses NTP to synchronize time: Accurate Time for Windows Server 2016 and Time accuracy improvements for Windows Server 2016.
This video shows the complexity of synchronizing time: The Obscure System That Syncs All The World's Clocks
#Conclusion
If your application needs to handle date and time, make sure you understand its requirements. In most cases, you can limit the scope of what needs to be supported. For example, does your application need to handle leap seconds, historical dates, or multiple time zones? Narrowing the scope simplifies the implementation and reduces the need to handle every edge case.
Do you have a question or a suggestion about this post? Contact me!