Sponsored Content
Top Forums UNIX for Advanced & Expert Users leap seconds and the stdc library Post 94268 by jim mcnamara on Wednesday 28th of December 2005 02:50:01 PM
Old 12-28-2005
leap seconds and the stdc library

I understand the NTP protocol, so keeping system time updated is not a problem.

Standard C library routines like localtime() take a number of UTC seconds elapsed since the start of the epoch (Jan 1, 1970). These times in seconds can be a filetime, system time, or some other time in the past or the future.

In order to translate the seconds into years, months, days, etc. correctly the routines have to know about leap seconds. Including the one coming up this Dec 31, there are 23 leap seconds since 1970.

How is this accomplished? -- knowing about newly hatched leap seconds?
BTW HPUX 11.00 C runtine does not do this correction.... VAX C did.

Code:
/* leapsecond.c */
#include <time.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	time_t when=strtoul(argv[1],(char **)0,10);
	struct tm *tmptr=gmtime(&when);
	
	printf("%s\n",asctime(tmptr));
	return 0;
}

gives this result:
kcsdev:/home/jmcnama> leapsecond 0
Thu Jan  1 00:00:00 1970

kcsdev:/home/jmcnama> leapsecond `echo "365*2*86400"|bc`
Sat Jan  1 00:00:00 1972

kcsdev:/home/jmcnama> leapsecond `echo "365*3*86400"|bc`
Sun Dec 31 00:00:00 1972

kcsdev:/home/jmcnama> leapsecond `echo "(365*3*86400)+86400"|bc`
Mon Jan  1 00:00:00 1973

There were two leap seconds in 1972, the translation does not take leap seconds into account.
 

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Insertion of Leap Second

Hi All, We are running the HP-UX 11.11 and Linux AS 3.0. so, shall we need to make any changes for leap second i.e. insert the leap second on 1st Jan 2006 or does the system have some setup which would take care of this automatically. Please advise. Regards, Inder (2 Replies)
Discussion started by: isingh786
2 Replies

2. HP-UX

Leap Second

Hi All, We are running the HP-UX 11.11 and Linux AS 3.0. so, shall we need to make any changes for leap second i.e. insert the leap second on 1st Jan 2006 or does the system have some setup which would take care of this automatically. Please advise. Regards, Inder (1 Reply)
Discussion started by: isingh786
1 Replies

3. UNIX for Dummies Questions & Answers

Leap year K-shell script

I need a k-shell script that tests for leap-year. Does anyone have one at hand, need ASAP!!! (2 Replies)
Discussion started by: p1jls02
2 Replies

4. UNIX for Dummies Questions & Answers

Number of leap seconds

Is there a function call in std library or unit command that returns the number of current leap seconds? GG (4 Replies)
Discussion started by: NAVTime
4 Replies

5. Shell Programming and Scripting

unix korn shell leap years problem

Write a function called dateToDays that takes three parameters -a month string such as Sep, a day number such as 18, and a year number such as 1962-and return s the number of days from January 1, 1900, to the date. Notes: I am asking you to account for leap years. my script is not... (0 Replies)
Discussion started by: babuda0059
0 Replies

6. Fedora

Leap second happening

Have anybody heard about the Leap second problem Leap second :A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC) in order to keep its time of day close to the mean solar time. How could i avoid such thing in my script which i deal with... (6 Replies)
Discussion started by: wnaguib
6 Replies

7. Solaris

Leap second for year 2015

I hear the Leap second for 2015 will occur on June 30 at 23:59:60 according to the wild rumours from internet the expected impact ranges from crashing to hanging servers. Can anybody share their preparations what they have done for solaris servers? are there any patches to install or workaround?... (1 Reply)
Discussion started by: sparcguy
1 Replies
Tcl_GetTime(3TCL)					      Tcl Library Procedures						 Tcl_GetTime(3TCL)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_GetTime - get date and time SYNOPSIS
#include <tcl.h> Tcl_GetTime( timePtr ) ARGUMENTS
Tcl_Time * timePtr (out) Points to memory in which to store the date and time information. _________________________________________________________________ DESCRIPTION
The Tcl_GetTime function retrieves the current time as a Tcl_Time structure in memory the caller provides. This structure has the follow- ing definition: typedef struct Tcl_Time { long sec; long usec; } Tcl_Time; On return, the sec member of the structure is filled in with the number of seconds that have elapsed since the epoch: the epoch is the point in time of 00:00 UTC, 1 January 1970. This number does not count leap seconds - an interval of one day advances it by 86400 seconds regardless of whether a leap second has been inserted. The usec member of the structure is filled in with the number of microseconds that have elapsed since the start of the second designated by sec. The Tcl library makes every effort to keep this number as precise as possible, subject to the limitations of the computer system. On multiprocessor variants of Windows, this number may be limited to the 10- or 20-ms granularity of the system clock. (On single-processor Windows systems, the usec field is derived from a performance counter and is highly precise.) SEE ALSO
clock KEYWORDS
date, time ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWTcl | +--------------------+-----------------+ |Interface Stability | Uncommitted | +--------------------+-----------------+ NOTES
Source for Tcl is available on http://opensolaris.org. Tcl 8.4 Tcl_GetTime(3TCL)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy