473,573 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 12787
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
9294
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 datetime strftime() methods require year >= 1900 Does anyone know of a datetime string formatter that can handles strftime format strings over the full...
4
7753
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 CANNOT use the inbuilt date functions or the DateTime Type. Your program should work with any date between 1900 and 3000. Here are your...
2
11001
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. But has someone already done what is necessary to get the number of seconds or minutes or hours between two DateTimes? Can one convert to ticks,...
4
4043
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 advanced for compatibility with many browsers in present-day use; that Web authors should be aware of what JScript and ..NET may do, but cannot rely...
10
10669
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 manually writing a function for it, and it just got uglier and uglier. And I figure it's something that someone has probably figured out before. Any...
37
4656
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 leap second? By "Unix time" I mean the integer returned by time() and similar functions. I'm concerned about the "down" case. Some of the...
37
14915
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: case 8: case 11: case 14: case 17: return 1; default: return 0;
0
16483
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 formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or...
2
2381
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 that they do not recognize the possiblity of having a leap-free broadcast time scale while still allowing leap seconds in UTC. Those really are two...
0
7765
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7681
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8194
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7767
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6398
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5578
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5288
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3729
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1294
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.