473,587 Members | 2,448 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unix Time and Leap Seconds

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 software I've written
assumes monotonically-increasing time.

Thanks.
--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jun 23 '07 #1
37 4663
Sig
On Sat, 23 Jun 2007 01:04:46 -0400 David T. Ashley said
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 software I've written
assumes monotonically-increasing time.
I don't think you have to worry.

(1) NIST says "Based on what we know about the earth's rotation, it seems
unlikely that we will ever have a negative leap second."
<http://tf.nist.gov/general/leaps.htm#Ancho r-52904>

(2) If it did happen, the time would repeat, not go backwards.

Sig

--
http://koiclubsandiego.org/comment/?r=8
9b9a436ac928556 7ef58d7d6a4dbb7 50
Jun 23 '07 #2
David T. Ashley wrote:
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 software I've written
assumes monotonically-increasing time.
Daylight saving (though how calling one time another saves daylight - there
will be exactly the same amount of daylight in the day regardless of what
you call the hours - I'm still trying to work out) are specified in a config
file (mefinx) and rarely change. Leap seconds I'm not so sure about - they
seem to be added semi-randomly (as and when the extremely constant and
accurate (for some definition of accurate) atomic clocks' day gets behind of
the slowing down earth rotation day).

Leap seconds will then mean that your clock is 1 second fast.

Personally I think you've probably got more concern from using a time server
to sync your computer's clock - the clock in this PC, for example, gains
quite a bit and so resyncing it adjusts it downward every time.

If you've got software that assumes monotonically increasing time, I'd
recommend you get a PC with a clock that loses time (ie it ticks at 1.00001
secs, as opposed to the 0.99999 secs of this PC) so that when re-syncing
your clock it will always adjust upwards. Besides, on a GHz processor,
seconds are rather a coarse measure anyway.

Jun 23 '07 #3
David T. Ashley wrote:
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 software I've written
assumes monotonically-increasing time.

Thanks.
Bad programming. What happens, for instance, if the clock on your
server is "corrected" back five seconds (possibly because it's running
fast)?

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Jun 23 '07 #4
On Sat, 23 Jun 2007 07:28:18 -0400, Jerry Stuckle <js*******@attg lobal.net>
wrote:
>Bad programming. What happens, for instance, if the clock on your
server is "corrected" back five seconds (possibly because it's running
fast)?
Well, that in turn would be bad server administration, since NTP tries to do
this by slowing the clock to maintain monotonic time - you have to be off by
minutes before it resorts to going backwards (and even then there's an option
to prevent it).

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jun 23 '07 #5
"Sig" <iv*****@exampl e.comwrote in message
news:MPG.20e65d 5b8466b27998968 1@islay...
On Sat, 23 Jun 2007 01:04:46 -0400 David T. Ashley said
>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 software I've written
assumes monotonically-increasing time.

I don't think you have to worry.

(1) NIST says "Based on what we know about the earth's rotation, it seems
unlikely that we will ever have a negative leap second."
<http://tf.nist.gov/general/leaps.htm#Ancho r-52904>

(2) If it did happen, the time would repeat, not go backwards.
If I'm understanding your comment correctly, and if I'm not mixed up myself,
I believe you have the sign wrong in the way you're thinking about leap
seconds. An ordinary (positive) leap second is where you insert an extra
second and "time stands still" for a second (this is akin to February 29).
I believe these will get more frequent as the earth's rotation is slowing
down.

An ordinary leap second ("time stands still") actually in effect gives the
earth's rotation time to "catch up" to the kept time.

A negative leap second would result in the Unix time skipping a second
(jumping forward).

Of course, "time standing still" can't happen on a computer system, so you
have to re-use a Unix time value (i.e. Unix time goes backwards).

So, I believe but am not sure that due to a sign mixup, the case that you
have presented as impossible is actually the normal and expected case.

According to the entry on Wikipedia,

http://en.wikipedia.org/wiki/Unix_time

Unix time will re-use certain integers when a leap second occurs. That
surprised me, but it may very well be true.

My application is generating unique identifiers in PHP (as part of web
database scripts). The current scheme I use is:

a)Concatenate the integer seconds time, the microtime, and the process PID,
and then

b)Spin lock or micro_sleep() until the microtime changes.

The identifiers generated should be unique because no two processes can have
the same PID at the same time.

I think the workaround I'll use (because leap seconds are handled at
midnight UTC) is that if I get an integer seconds time that is too close to
a midnight (i.e. mod 86400 is <=1 or >=86398), then I'll just sleep until it
gets out of that range. That leaves approximately 4 seconds near midnight
UTC where a web page load may hang for up to 4 seconds. That seems very
tolerable, because the window is so narrow and because the web page will
eventually load.

Anyone want to throw rocks at me and tell me I'm crazy?

Thanks for all input.

Dave.
--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jun 23 '07 #6
Robert Newson wrote:
though how calling one time another saves daylight -
there will be exactly the same amount of daylight in the day regardless
of what you call the hours - I'm still trying to work out
.... tedious rhetoric ...
Jun 23 '07 #7
David T. Ashley wrote:
I'm concerned about the "down" case. Some of the software I've written
assumes monotonically-increasing time.
If you're concerned then bullet proof your code in case it does happen.
Jun 23 '07 #8
On Sat, 23 Jun 2007, in the Usenet newsgroup comp.os.linux, in article
<09************ *************** ***@giganews.co m>, David T. Ashley wrote:
>I have Red Hat Enterprise Linux 4.

I was just reading up about UTC and leap seconds.
You'll want to look at

-rw-rw-r-- 1 gferg ldp 43295 Nov 18 2005 TimePrecision-HOWTO

TimePrecision-HOWTO, Managing Accurate Date and Time HOWTO
Updated: Nov 2005. Explains the time mechanisms on Linux, what are
time zones, and precision with NTP.
>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?
No. Your system time will wander along as usual. If you have installed
and configured an NTP _client_ application, your time will _SLEW_ to
make up for the one second error. See the several RFCs that relate to
Network Time, such as

1305 Network Time Protocol (Version 3) Specification, Implementation
and Analysis. D. Mills. March 1992. (Format: TXT=307085, PDF=442493
bytes) (Obsoletes RFC0958, RFC1059, RFC1119) (Status: DRAFT STANDARD)

4330 Simple Network Time Protocol (SNTP) Version 4 for IPv4, IPv6 and
OSI. D. Mills. January 2006. (Format: TXT=67930 bytes) (Obsoletes
RFC2030, RFC1769) (Status: INFORMATIONAL)

as well as the documentation for your NTP client.
>By "Unix time" I mean the integer returned by time() and similar functions.
time(2) returns seconds since the UNIX epoch. Note that NTP time is
using a different epoch (1/1/1900), but an NTP timestamp really a
truncated NTP date expressed as an unsigned 64-bit integer including the
low order 32 bits of the seconds field concatenated with the high-order
32 bits of the fraction field. This format can represent the 136 years
from 1900 to 2036 with a precision of 232 picoseconds. Ranges beyond
these years require an era number which is the high order 32 bits of the
seconds field of the associated date. Your NTP client corrects for the
difference in epochs when tweaking the time. See
http://www.cis.udel.edu/~mills/y2k.html for more details.
>I'm concerned about the "down" case. Some of the software I've written
assumes monotonically-increasing time.
So does Professor Mills, who has been in this racket for a "few" years.
If you are interested, you may wish to review recent posts in the Usenet
newgroup 'comp.protocols .time.ntp' which is carried on this news server.
Obviously you aren't concerned with Daylight Saving Time, which has
nothing to do with time(2), or the timestep that occurs when your
system is booting (before client applications start).

Old guy
Jun 23 '07 #9
On Sat, 23 Jun 2007, in the Usenet newsgroup comp.os.linux, in article
<46************ **@bullet3.fsne t.oc.ku>, Robert Newson wrote:
>David T. Ashley wrote:
>I was just reading up about UTC and leap seconds.
>By "Unix time" I mean the integer returned by time() and similar
functions.
[compton ~]$ whatis time
time (2) - get time in seconds
[compton ~]$
>Daylight saving (though how calling one time another saves daylight -
there will be exactly the same amount of daylight in the day regardless
of what you call the hours - I'm still trying to work out) are
specified in a configfile (mefinx) and rarely change.
Neither UTC or 'time(2)' know anything about Daylight Saving Time
>Leap seconds I'm not so sure about - they seem to be added semi-randomly
(as and when the extremely constant and accurate (for some definition of
accurate) atomic clocks' day gets behind of the slowing down earth
rotation day).
From the 'leapsecond' file in the timezone source file tzdata2007f.tar .gz
available from ftp://elsie.nci.nih.gov/pub/

# YEAR MONTH DAY HH:MM:SS CORR YEAR MONTH DAY HH:MM:SS CORR
1972 Jun 30 23:59:60 + 1972 Dec 31 23:59:60 +
1973 Dec 31 23:59:60 + 1974 Dec 31 23:59:60 +
1975 Dec 31 23:59:60 + 1976 Dec 31 23:59:60 +
1977 Dec 31 23:59:60 + 1978 Dec 31 23:59:60 +
1979 Dec 31 23:59:60 + 1981 Jun 30 23:59:60 +
1982 Jun 30 23:59:60 + 1983 Jun 30 23:59:60 +
1985 Jun 30 23:59:60 + 1987 Dec 31 23:59:60 +
1989 Dec 31 23:59:60 + 1990 Dec 31 23:59:60 +
1992 Jun 30 23:59:60 + 1993 Jun 30 23:59:60 +
1994 Jun 30 23:59:60 + 1995 Dec 31 23:59:60 +
1997 Jun 30 23:59:60 + 1998 Dec 31 23:59:60 +
2005 Dec 31 23:59:60 +

Relatively random, no?
>Personally I think you've probably got more concern from using a time server
to sync your computer's clock - the clock in this PC, for example, gains
quite a bit and so resyncing it adjusts it downward every time.
You seem to be posting from a Linux box - see the TimePrecision-HOWTO
which should be on your system (or get it from the LDP).
>If you've got software that assumes monotonically increasing time, I'd
recommend you get a PC with a clock that loses time (ie it ticks at 1.00001
secs, as opposed to the 0.99999 secs of this PC) so that when re-syncing
your clock it will always adjust upwards.
You really want to look at the NTP client documentation, or even

[compton ~]$ whatis adjtimex
adjtimex (2) - tune kernel clock
adjtimex (8) - display or set the kernel time variables
[compton ~]$
>Besides, on a GHz processor, seconds are rather a coarse measure anyway.
as well as how "time" is measured - it has nothing to do with the CPU
clock frequency. "INT0" (cat /proc/interrupts) is generated by a
separate (equally crappy) oscillator.

Old guy
Jun 23 '07 #10

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

Similar topics

6
3492
by: Charles Hixson | last post by:
This is a concept, not a finished program, and an extract from a class at that...so forgive any illegalities, but: import datetime; def calcNodeId(self): t = datetime.utcnow() val = t.year * 133920000000 + # 12 months t.month * 11160000000 + # 31 days t.hour * 3600000000 + ...
5
4686
by: Tom | last post by:
A field in a data set I want to import into Access is in Unix time (seconds from a certain time on a certain date). Does anyone know the precise date and the precise time on that date that Unix is based on? How do I calculate the Date when I have Unix seconds? Will the calculation take into account leap years? Thanks! Tom
13
20633
by: Huey | last post by:
Hi All, I need to compute the current time value in seconds: the current time is 12/16/2003, and it's time value in integer should around 1071560616 seconds since 1/1/1970. It is easy to get such a value in Tcl, but i noticed it is uneasy to do in C. Well, ANSI provides functions such as time(), asctime(), localtime(), gmtime(), ctime() in...
14
2482
by: George | last post by:
In Time.h there is a structure defined for time settings. I'm building an embedded system that has a Real Time Clock but it's not PC compatible. My question is: I don't some elements of the structure such as day of the week or day of the year, but I do know year,month,date,hour,min,sec. Does the language support filling in the missing...
6
34077
by: marc | last post by:
hi im trying to convert Date() into a unix timestamp so i can stick the result into a mysql db, please help!
5
8502
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions expect positive offsets from this date and are incapable of working on dates preceeding the epoch (i.e. negative offsets) - which IMHO shows a...
11
573
by: usenet | last post by:
Is the epoch time the number of seconds elapsed since January 1st 1970 in my timezone or as per UTC? I mean, if A's program makes a call to time() in Melboune and B's program makes a call to time() in Montreal AT THIS VERY INSTANT, will they return the same values, or will A's program return a value that is more than B's value by 36000 (since...
17
3761
by: Andrew Chalk | last post by:
Network time uses 1900 as its base. The C time library uses 1970. I want to convert a network time value to a C library time. I.e. I have to subtract the number of seconds from 1900 to 1970. Is there any library function to do this? Thanks.
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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
7973
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
6626
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...
0
5394
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
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.