In 2012, there was a question here on SO, whether .NET's DateTime are capable of recognizing leap seconds. [1] The answer was no.
The documentation is still explicitly stating that it is not. [2]
However, Windows Server 2019 and the Windows 10 October 2018 update made Windows itself leap second aware. [3]
This begs the question: is .NET inherently leap second aware now? More specifically: can I make my DateTime
structures leap second aware as well, by somehow opting in?
Edit:
From a MS Word document titled "Quest: Write a Leap Second Aware Application on Windows" [4] (emphasis by me):
Known issues: Some frameworks are known to calculate time incorrectly after a leap second occurs. For example, the .NET Framework uses its own internal logic to determine what time it is. Its logic does not account for leap seconds. So after a leap second is introduced to the Operating System the output of “System.DateTime.Now.ToString()” will be ahead by one second of the local system time. (We are working with the .NET framework team on this.)
And from [5]:
Some applications are known to calculate time incorrectly by assuming that there are always 60 seconds in a minute. Since leap seconds can change this behavior, they will improperly record the time during this event. For example (at the time of writing):
.NET Framework uses its own internal logic to determine what time it is and does not account for leap seconds. As a result, PowerShell, which relies on the .NET Framework, will not report the 61st second (number 60) when using Get-Date
Event Viewer: The date of the event will be incorrectly recorded. However, the event metadata will properly record the system time (showing the 60th second).
Note: These teams are working towards updating their software to use more appropriate math when handling leap seconds.
So it seems that .NET will be leap second aware some time in the future. Thus I will not post this as the solution.
[1] Are .Net's DateTime methods capable of recognising a Leap Second?
[3] https://support.microsoft.com/en-us/help/2722715/support-for-the-leap-second
[4] https://aka.ms/Dev-LeapSecond (MS Word)
[5] https://aka.ms/ITPro-LeapSecond (MS Word)