Fixed license declaration at spec file
[platform/upstream/tzdata.git] / time2posix.3
1 .TH TIME2POSIX 3
2 .SH NAME
3 time2posix, posix2time \- convert seconds since the Epoch
4 .SH SYNOPSIS
5 .nf
6 .ie \n(.g .ds - \f(CW-\fP
7 .el ds - \-
8 .B #include <time.h>
9 .PP
10 .B time_t time2posix(time_t t);
11 .PP
12 .B time_t posix2time(time_t t);
13 .PP
14 .B cc ... \*-ltz
15 .fi
16 .SH DESCRIPTION
17 .ie '\(en'' .ds en \-
18 .el .ds en \(en
19 .ie '\(lq'' .ds lq \&"\"
20 .el .ds lq \(lq\"
21 .ie '\(rq'' .ds rq \&"\"
22 .el .ds rq \(rq\"
23 .de q
24 \\$3\*(lq\\$1\*(rq\\$2
25 ..
26 IEEE Standard 1003.1
27 (POSIX)
28 requires the time_t value 536457599 to stand for 1986-12-31 23:59:59 UTC.
29 This effectively implies that POSIX time_t values cannot include leap
30 seconds and,
31 therefore,
32 that the system time must be adjusted as each leap occurs.
33 .PP
34 If the time package is configured with leap-second support
35 enabled,
36 however,
37 no such adjustment is needed and
38 time_t values continue to increase over leap events
39 (as a true
40 .q "seconds since..."
41 value).
42 This means that these values will differ from those required by POSIX
43 by the net number of leap seconds inserted since the Epoch.
44 .PP
45 Typically this is not a problem as the type time_t is intended
46 to be
47 (mostly)
48 opaque \*(en time_t values should only be obtained-from and
49 passed-to functions such as
50 .IR time(2) ,
51 .IR localtime(3) ,
52 .IR mktime(3) ,
53 and
54 .IR difftime(3) .
55 However,
56 POSIX gives an arithmetic
57 expression for directly computing a time_t value from a given date/time,
58 and the same relationship is assumed by some
59 (usually older)
60 applications.
61 Any programs creating/dissecting time_t's
62 using such a relationship will typically not handle intervals
63 over leap seconds correctly.
64 .PP
65 The
66 .I time2posix
67 and
68 .I posix2time
69 functions are provided to address this time_t mismatch by converting
70 between local time_t values and their POSIX equivalents.
71 This is done by accounting for the number of time-base changes that
72 would have taken place on a POSIX system as leap seconds were inserted
73 or deleted.
74 These converted values can then be used in lieu of correcting the older
75 applications,
76 or when communicating with POSIX-compliant systems.
77 .PP
78 .I Time2posix
79 is single-valued.
80 That is,
81 every local time_t
82 corresponds to a single POSIX time_t.
83 .I Posix2time
84 is less well-behaved:
85 for a positive leap second hit the result is not unique,
86 and for a negative leap second hit the corresponding
87 POSIX time_t doesn't exist so an adjacent value is returned.
88 Both of these are good indicators of the inferiority of the
89 POSIX representation.
90 .PP
91 The following table summarizes the relationship between a time
92 T and it's conversion to,
93 and back from,
94 the POSIX representation over the leap second inserted at the end of June,
95 1993.
96 .nf
97 .ta \w'93/06/30 'u +\w'23:59:59 'u +\w'A+0 'u +\w'X=time2posix(T) 'u
98 DATE    TIME    T       X=time2posix(T) posix2time(X)
99 93/06/30        23:59:59        A+0     B+0     A+0
100 93/06/30        23:59:60        A+1     B+1     A+1 or A+2
101 93/07/01        00:00:00        A+2     B+1     A+1 or A+2
102 93/07/01        00:00:01        A+3     B+2     A+3
103
104 A leap second deletion would look like...
105
106 DATE    TIME    T       X=time2posix(T) posix2time(X)
107 ??/06/30        23:59:58        A+0     B+0     A+0
108 ??/07/01        00:00:00        A+1     B+2     A+1
109 ??/07/01        00:00:01        A+2     B+3     A+2
110 .sp
111 .ce
112         [Note: posix2time(B+1) => A+0 or A+1]
113 .fi
114 .PP
115 If leap-second support is not enabled,
116 local time_t's and
117 POSIX time_t's are equivalent,
118 and both
119 .I time2posix
120 and
121 .I posix2time
122 degenerate to the identity function.
123 .SH SEE ALSO
124 difftime(3),
125 localtime(3),
126 mktime(3),
127 time(2)
128 .\" This file is in the public domain, so clarified as of
129 .\" 1996-06-05 by Arthur David Olson.