.NET Does not Support Leap Seconds

April 13th, 2008

In my seemingly never ending quest to understand how accurately represent dates and times worldwide, I found out that .NET does not support leap seconds.  For those of you unfamiliar with the concept, “The Wikipedia” has a nice introduction.  Basically UTC uses an atomic clock to keep time (read: accurate) and the rest of us use a spinning ball circling another spinning ball to keep time (read: inaccurate).  The net result is we need to add or subtract a second here and there to keep things in line.  This is in addition to that whole day we throw into the mix every four years or so.

Anywhoo, this forum question raises some valid questions, so I did a quick check on my own and the following code does indeed throw an exception when it shouldn’t:

DateTime foo = new DateTime(2005, 12, 31, 23, 59, 60, DateTimeKind.Utc);

The MSDN documentation is mum on the issue, so I think it’s safe to say that this wasn’t a consideration.  It even specifically says that the second value will be on the range [0, 59].  This is just something to be aware of if you’re implementing a protocol that does support leap seconds, such as the iCalendar specification.

As an aside, this site is a good reference for all sorts of mistakes programmers make when working with dates & times.

Entry Filed under: .NET

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

April 2008
M T W T F S S
« Mar   Jun »
 123456
78910111213
14151617181920
21222324252627
282930  

Most Recent Posts