473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DateTime accounts for leap seconds ?!


In the documentation, the "Second" property of class
DateTime is a value between 0 and 59.

In UTC time, approximately every year of so, a leap
second is added at 00:00:00 UTC, so as to account for the
irregular rotation of the earth, which is slowing down a
little bit.
So, a minute can contains 61 seconds ( range 0..60 ).
Besides, the NTP protocol takes leap second into account,
and UTC time also.

Is it possible for DateTime to return 60 for the "Second"
property ?
Does it depends on the underlying OS ?
Or does a minute always contains 60 seconds for the class
DateTime ? ( which means an interval of time can be
physically 11 seconds long, even if the difference
computed from Datetime values is 10 seconds only, if a
leap second occurs in-between )...

Any suggestion ?


Nov 15 '05 #1
3 12714
There are always 60 seconds in a minute, 60 minutes in an hour, 24 hours in
a day... *always*. There is no "leap second" added at any time or any place
on earth. What happens is that it take the earth's 365.2422 days to do a
complete revolution around the sun. Here's where the fun starts.

Leap *days* are needed to keep our callendar aligned with the earth's motion
around the sun. Bear in mind I said days... whole, complete days. There's a
whole set of rules as to how you calculate whether or not a year has a leap
day added or not (http://www.timeanddate.com/date/leapyear.html).

So, of course, DateTime seconds account only for the 60 possible seconds of
a minute (ranging from 0..59, as you pointed out).

-JG

Nov 15 '05 #2
There are always 60 seconds in a minute, 60 minutes in an hour, 24 hours ina day... *always*. There is no "leap second" added at any time or any placeon earth.


I know, leap seconds are a pain in the ass. When someone
use a time library, he must know the conditions in which
he can use it. I mean, if the library handles leap
seconds, and how it copes with them. The number of ticks
for a given date could change if leap seconds are
accounted for.

UTC is now quite the reference for civil time, and it is
based on atomic clock, more accurate than the period of
rotation of earth, which varies slightly and is not as
periodic as it should be.

From http://www.npl.co.uk/time/leap_second.html, we have
an example:
1998 December 31 23h 59m 58s
1998 December 31 23h 59m 59s
1998 December 31 23h 59m 60s (here, leap second inserted)
1999 January 01 00h 00m 00s
1999 January 01 00h 00m 01s

In C and Java, and certainly lots of other languages,
leap seconds are taken into account, if the underlying OS
support it.

Quoting from the Java Language Specification about class
java.util.Date:
"A second is represented by an integer from 0 to 61. The
values 60 and 61 will occur only for leap seconds, and
even then only in Java implementations that actually
track leap seconds correctly. Because of the manner in
which leap seconds are currently introduced, it is
extremely unlikely that two leap seconds will occur in
the same minute, but this specification follows the date
and time conventions for ISO C."

Same problem about C. Quoting from any libc reference:
struct tm: This is the data type used to represent a
broken-down time.
int tm_sec: This is the number of full seconds since the
top of the minute (normally in the range 0 through 59,
but the actual upper limit is 60, to allow for leap
seconds if leap second support is available).

http://tycho.usno.navy.mil/leapsec.html
http://www.leapsecond.com/java/gpsclock.htm

Any other suggestion ?
Nov 15 '05 #3

In the doc for .NET Framework Class Library, in msdn
library, I read:

DateTime Structure:
Descriptions of time values in this type are often
expressed using the coordinated universal time (UTC)
standard, which was previously known as Greenwich mean
time (GMT).

DateTime.UtcNow Property:
Gets a DateTime that is the current local date and time
on this computer expressed as the coordinated universal
time (UTC).

DateTime.Second Property:
The seconds, between 0 and 59.

DateTime.Ticks Property:
The value of this property is the number of 100-
nanosecond intervals that have elapsed since 12:00 A.M.,
January 1, 0001.

---------------

Those specifications are totally incoherent.

1) UTC is based on atomic clock, and includes leap
seconds.
A minute in UTC time can thus be 59, 60, 61, 62
seconds long.

2) If DateTime.UtcNow returns a DateTime as UTC, then the
minute property of the returned value can be 59, 60, 61,
or 62 seconds, because UTC time includes leap seconds. If
not, the returned value is not UTC time.

3) If DateTime.Second property only ranges from 0 to 59,
then Datetime is not really UTC time.

4) UTC is based on atomic clock, GMT is based on earth
rotation. It is absolutely not the same thing.

5) DateTime.Ticks returns the number of ticks, but
following which standard. UTC ?

Someone can clarify all this mess ?
Does the behaviour of DateTime depends on the underlying
system ? or on the implementation of .NET library ?

thanks
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
4
by: Russell | last post by:
I have an assignment that I have to complete. I have to write a windows app in C#. Here is the spec: 1/ Date Comparison Build a program that will find the number of days between two dates. You...
2
by: Randall Parker | last post by:
I know I could just get the year,month,day, etc of of each DateTime vars and calc the hours difference between them. I've done this before in other languages with a formula for handling leap years....
4
by: Dr John Stockton | last post by:
I'm starting a new thread, for clarity. I'm assuming that it's ECMA-262 3rd Edn (1999) that we should be using for Web pages; that 4th Edn (what's its present status? is it available?) is too...
10
by: David P. Donahue | last post by:
Can anyone think of an easy way to take two DateTime values and calculate, with double precision, how many semi-monthly (the first and the fifteenth) pay periods occur between them? I started...
37
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a...
37
by: mazwolfe | last post by:
I'm new here, so excuse me if my style is incorrect. Can anyone come up with a better method for this calculation? Code: int is_leap(int year) { switch (year % 19) { case 0: case 3: case 6:...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
2
by: Robert Jones | last post by:
I thought the following link could be of interest: The USNO is conducting a poll for the DoD about leap seconds. http://tycho.usno.navy.mil/leap_second_poll.html I note in the description...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.