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