1*bc421551SDag-Erling Smørgrav.\" This file is in the public domain, so clarified as of 2*bc421551SDag-Erling Smørgrav.\" 1996-06-05 by Arthur David Olson. 3*bc421551SDag-Erling Smørgrav.\" 4*bc421551SDag-Erling Smørgrav.\" $FreeBSD$ 5*bc421551SDag-Erling Smørgrav.\" 6*bc421551SDag-Erling Smørgrav.Dd December 15, 2022 7*bc421551SDag-Erling Smørgrav.Dt TIME2POSIX 3 8*bc421551SDag-Erling Smørgrav.Os 9*bc421551SDag-Erling Smørgrav.Sh NAME 10*bc421551SDag-Erling Smørgrav.Nm time2posix , 11*bc421551SDag-Erling Smørgrav.Nm posix2time 12*bc421551SDag-Erling Smørgrav.Nd convert seconds since the Epoch 13*bc421551SDag-Erling Smørgrav.Sh LIBRARY 14*bc421551SDag-Erling Smørgrav.Lb libc 15*bc421551SDag-Erling Smørgrav.Sh SYNOPSIS 16*bc421551SDag-Erling Smørgrav.In time.h 17*bc421551SDag-Erling Smørgrav.Ft time_t 18*bc421551SDag-Erling Smørgrav.Fn time2posix "time_t t" 19*bc421551SDag-Erling Smørgrav.Ft time_t 20*bc421551SDag-Erling Smørgrav.Fn posix2time "time_t t" 21*bc421551SDag-Erling Smørgrav.Sh DESCRIPTION 22*bc421551SDag-Erling Smørgrav.St -p1003.1-88 23*bc421551SDag-Erling Smørgravrequires the time_t value 536457599 to stand for 1986-12-31 23:59:59 UTC. 24*bc421551SDag-Erling SmørgravThis effectively implies that POSIX 25*bc421551SDag-Erling Smørgrav.Vt time_t 26*bc421551SDag-Erling Smørgravvalues cannot include leap 27*bc421551SDag-Erling Smørgravseconds and, 28*bc421551SDag-Erling Smørgravtherefore, 29*bc421551SDag-Erling Smørgravthat the system time must be adjusted as each leap occurs. 30*bc421551SDag-Erling Smørgrav.Pp 31*bc421551SDag-Erling SmørgravIf the time package is configured with leap-second support 32*bc421551SDag-Erling Smørgravenabled, 33*bc421551SDag-Erling Smørgravhowever, 34*bc421551SDag-Erling Smørgravno such adjustment is needed and 35*bc421551SDag-Erling Smørgrav.Vt time_t 36*bc421551SDag-Erling Smørgravvalues continue to increase over leap events 37*bc421551SDag-Erling Smørgrav(as a true 38*bc421551SDag-Erling Smørgrav.Dq "seconds since..." 39*bc421551SDag-Erling Smørgravvalue). 40*bc421551SDag-Erling SmørgravThis means that these values will differ from those required by POSIX 41*bc421551SDag-Erling Smørgravby the net number of leap seconds inserted since the Epoch. 42*bc421551SDag-Erling Smørgrav.Pp 43*bc421551SDag-Erling SmørgravTypically this is not a problem as the type 44*bc421551SDag-Erling Smørgrav.Vt time_t 45*bc421551SDag-Erling Smørgravis intended 46*bc421551SDag-Erling Smørgravto be 47*bc421551SDag-Erling Smørgrav(mostly) 48*bc421551SDag-Erling Smørgravopaque \(em 49*bc421551SDag-Erling Smørgrav.Vt time_t 50*bc421551SDag-Erling Smørgravvalues should only be obtained-from and 51*bc421551SDag-Erling Smørgravpassed-to functions such as 52*bc421551SDag-Erling Smørgrav.Xr time 3 , 53*bc421551SDag-Erling Smørgrav.Xr localtime 3 , 54*bc421551SDag-Erling Smørgrav.Xr mktime 3 55*bc421551SDag-Erling Smørgravand 56*bc421551SDag-Erling Smørgrav.Xr difftime 3 . 57*bc421551SDag-Erling SmørgravHowever, 58*bc421551SDag-Erling Smørgrav.St -p1003.1-88 59*bc421551SDag-Erling Smørgravgives an arithmetic 60*bc421551SDag-Erling Smørgravexpression for directly computing a 61*bc421551SDag-Erling Smørgrav.Vt time_t 62*bc421551SDag-Erling Smørgravvalue from a given date/time, 63*bc421551SDag-Erling Smørgravand the same relationship is assumed by some 64*bc421551SDag-Erling Smørgrav(usually older) 65*bc421551SDag-Erling Smørgravapplications. 66*bc421551SDag-Erling SmørgravAny programs creating/dissecting 67*bc421551SDag-Erling Smørgrav.Vt time_t 68*bc421551SDag-Erling Smørgravvalues 69*bc421551SDag-Erling Smørgravusing such a relationship will typically not handle intervals 70*bc421551SDag-Erling Smørgravover leap seconds correctly. 71*bc421551SDag-Erling Smørgrav.Pp 72*bc421551SDag-Erling SmørgravThe 73*bc421551SDag-Erling Smørgrav.Fn time2posix 74*bc421551SDag-Erling Smørgravand 75*bc421551SDag-Erling Smørgrav.Fn posix2time 76*bc421551SDag-Erling Smørgravfunctions are provided to address this 77*bc421551SDag-Erling Smørgrav.Vt time_t 78*bc421551SDag-Erling Smørgravmismatch by converting 79*bc421551SDag-Erling Smørgravbetween local 80*bc421551SDag-Erling Smørgrav.Vt time_t 81*bc421551SDag-Erling Smørgravvalues and their POSIX equivalents. 82*bc421551SDag-Erling SmørgravThis is done by accounting for the number of time-base changes that 83*bc421551SDag-Erling Smørgravwould have taken place on a POSIX system as leap seconds were inserted 84*bc421551SDag-Erling Smørgravor deleted. 85*bc421551SDag-Erling SmørgravThese converted values can then be used in lieu of correcting the older 86*bc421551SDag-Erling Smørgravapplications, 87*bc421551SDag-Erling Smørgravor when communicating with POSIX-compliant systems. 88*bc421551SDag-Erling Smørgrav.Pp 89*bc421551SDag-Erling SmørgravThe 90*bc421551SDag-Erling Smørgrav.Fn time2posix 91*bc421551SDag-Erling Smørgravfunction 92*bc421551SDag-Erling Smørgravis single-valued. 93*bc421551SDag-Erling SmørgravThat is, 94*bc421551SDag-Erling Smørgravevery local 95*bc421551SDag-Erling Smørgrav.Vt time_t 96*bc421551SDag-Erling Smørgravcorresponds to a single POSIX 97*bc421551SDag-Erling Smørgrav.Vt time_t . 98*bc421551SDag-Erling SmørgravThe 99*bc421551SDag-Erling Smørgrav.Fn posix2time 100*bc421551SDag-Erling Smørgravfunction 101*bc421551SDag-Erling Smørgravis less well-behaved: 102*bc421551SDag-Erling Smørgravfor a positive leap second hit the result is not unique, 103*bc421551SDag-Erling Smørgravand for a negative leap second hit the corresponding 104*bc421551SDag-Erling SmørgravPOSIX 105*bc421551SDag-Erling Smørgrav.Vt time_t 106*bc421551SDag-Erling Smørgravdoes not exist so an adjacent value is returned. 107*bc421551SDag-Erling SmørgravBoth of these are good indicators of the inferiority of the 108*bc421551SDag-Erling SmørgravPOSIX representation. 109*bc421551SDag-Erling Smørgrav.Pp 110*bc421551SDag-Erling SmørgravThe following table summarizes the relationship between a time 111*bc421551SDag-Erling SmørgravT and its conversion to, 112*bc421551SDag-Erling Smørgravand back from, 113*bc421551SDag-Erling Smørgravthe POSIX representation over the leap second inserted at the end of June, 114*bc421551SDag-Erling Smørgrav1993. 115*bc421551SDag-Erling Smørgrav.Bl -column "93/06/30" "23:59:59" "A+0" "X=time2posix(T)" 116*bc421551SDag-Erling Smørgrav.It Sy "DATE TIME T X=time2posix(T) posix2time(X)" 117*bc421551SDag-Erling Smørgrav.It "93/06/30 23:59:59 A+0 B+0 A+0" 118*bc421551SDag-Erling Smørgrav.It "93/06/30 23:59:60 A+1 B+1 A+1 or A+2" 119*bc421551SDag-Erling Smørgrav.It "93/07/01 00:00:00 A+2 B+1 A+1 or A+2" 120*bc421551SDag-Erling Smørgrav.It "93/07/01 00:00:01 A+3 B+2 A+3" 121*bc421551SDag-Erling Smørgrav.El 122*bc421551SDag-Erling Smørgrav.Pp 123*bc421551SDag-Erling SmørgravA leap second deletion would look like... 124*bc421551SDag-Erling Smørgrav.Bl -column "??/06/30" "23:59:58" "A+0" "X=time2posix(T)" 125*bc421551SDag-Erling Smørgrav.It Sy "DATE TIME T X=time2posix(T) posix2time(X)" 126*bc421551SDag-Erling Smørgrav.It "??/06/30 23:59:58 A+0 B+0 A+0" 127*bc421551SDag-Erling Smørgrav.It "??/07/01 00:00:00 A+1 B+2 A+1" 128*bc421551SDag-Erling Smørgrav.It "??/07/01 00:00:01 A+2 B+3 A+2" 129*bc421551SDag-Erling Smørgrav.El 130*bc421551SDag-Erling Smørgrav.Pp 131*bc421551SDag-Erling Smørgrav.D1 No "[Note: posix2time(B+1) => A+0 or A+1]" 132*bc421551SDag-Erling Smørgrav.Pp 133*bc421551SDag-Erling SmørgravIf leap-second support is not enabled, 134*bc421551SDag-Erling Smørgravlocal 135*bc421551SDag-Erling Smørgrav.Vt time_t 136*bc421551SDag-Erling Smørgravand 137*bc421551SDag-Erling SmørgravPOSIX 138*bc421551SDag-Erling Smørgrav.Vt time_t 139*bc421551SDag-Erling Smørgravvalues are equivalent, 140*bc421551SDag-Erling Smørgravand both 141*bc421551SDag-Erling Smørgrav.Fn time2posix 142*bc421551SDag-Erling Smørgravand 143*bc421551SDag-Erling Smørgrav.Fn posix2time 144*bc421551SDag-Erling Smørgravdegenerate to the identity function. 145*bc421551SDag-Erling Smørgrav.Sh "SEE ALSO" 146*bc421551SDag-Erling Smørgrav.Xr difftime 3 , 147*bc421551SDag-Erling Smørgrav.Xr localtime 3 , 148*bc421551SDag-Erling Smørgrav.Xr mktime 3 , 149*bc421551SDag-Erling Smørgrav.Xr time 3 150