Description
At the time of writing, the documentation reads
represents the number of seconds that have elapsed
and
does not take leap seconds into account
I found this wording confusing. At first reading, I questioned whether the calculation treated leap seconds differently from absolute monotonic seconds, as it should. Based on cursory tests, I can see that calculations are correctly performed in the calendar domain (UTC), not the time domain (TAI). The best wording I have seen to date is this, by Markus Kuhn:
The POSIX second count ignores inserted leap seconds (and does not even provide an encoding for them) and counts deleted leap seconds
In practice, unix time represents a UTC date and time as a set of fields packed into an integer value according to a formula set by POSIX. The companion definition of unix time as a measure of elapsed time cannot be reconciled with this formula; it is effectively a false correspondence rooted in history and is a common source of error. It appears that ToUnixTimeSeconds uses the latter definition and conforms because the DateTimeOffset.Ticks shares the same limitation regarding leap seconds. The documentation there is more clear:
It does not include ticks that would be added by leap seconds.
(edited to fix blockquote)
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 265528c3-9318-aa3c-6c32-a6a2b2b2cedd
- Version Independent ID: 92ea6e5d-653f-ac43-a3bf-9348fc3a0a0f
- Content: DateTimeOffset.ToUnixTimeSeconds Method (System)
- Content Source: xml/System/DateTimeOffset.xml
- Product: dotnet-api
- GitHub Login: @dotnet-bot
- Microsoft Alias: dotnetcontent