Reply to Re: Unix Time and Leap Seconds

Your name:

Reply:


Posted by David T. Ashley on 06/23/07 14:44

"Sig" <ivanlid@example.com> wrote in message
news:MPG.20e65d5b8466b279989681@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#Anchor-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 (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация