1 TIME2POSIX(3) Library Functions Manual TIME2POSIX(3)
4 time2posix, posix2time - convert seconds since the Epoch
9 time_t time2posix(time_t t);
11 time_t posix2time(time_t t);
16 IEEE Standard 1003.1 (POSIX) requires the time_t value 536457599 to
17 stand for 1986-12-31 23:59:59 UTC. This effectively implies that POSIX
18 time_t values cannot include leap seconds and, therefore, that the
19 system time must be adjusted as each leap occurs.
21 If the time package is configured with leap-second support enabled,
22 however, no such adjustment is needed and time_t values continue to
23 increase over leap events (as a true "seconds since..." value). This
24 means that these values will differ from those required by POSIX by the
25 net number of leap seconds inserted since the Epoch.
27 Typically this is not a problem as the type time_t is intended to be
28 (mostly) opaque - time_t values should only be obtained-from and
29 passed-to functions such as time(2), localtime(3), mktime(3), and
30 difftime(3). However, POSIX gives an arithmetic expression for
31 directly computing a time_t value from a given date/time, and the same
32 relationship is assumed by some (usually older) applications. Any
33 programs creating/dissecting time_t's using such a relationship will
34 typically not handle intervals over leap seconds correctly.
36 The time2posix and posix2time functions are provided to address this
37 time_t mismatch by converting between local time_t values and their
38 POSIX equivalents. This is done by accounting for the number of time-
39 base changes that would have taken place on a POSIX system as leap
40 seconds were inserted or deleted. These converted values can then be
41 used in lieu of correcting the older applications, or when
42 communicating with POSIX-compliant systems.
44 Time2posix is single-valued. That is, every local time_t corresponds
45 to a single POSIX time_t. Posix2time is less well-behaved: for a
46 positive leap second hit the result is not unique, and for a negative
47 leap second hit the corresponding POSIX time_t doesn't exist so an
48 adjacent value is returned. Both of these are good indicators of the
49 inferiority of the POSIX representation.
51 The following table summarizes the relationship between a time T and
52 it's conversion to, and back from, the POSIX representation over the
53 leap second inserted at the end of June, 1993.
54 DATE TIME T X=time2posix(T) posix2time(X)
55 93/06/30 23:59:59 A+0 B+0 A+0
56 93/06/30 23:59:60 A+1 B+1 A+1 or A+2
57 93/07/01 00:00:00 A+2 B+1 A+1 or A+2
58 93/07/01 00:00:01 A+3 B+2 A+3
60 A leap second deletion would look like...
62 DATE TIME T X=time2posix(T) posix2time(X)
63 ??/06/30 23:59:58 A+0 B+0 A+0
64 ??/07/01 00:00:00 A+1 B+2 A+1
65 ??/07/01 00:00:01 A+2 B+3 A+2
67 [Note: posix2time(B+1) => A+0 or A+1]
69 If leap-second support is not enabled, local time_t's and POSIX
70 time_t's are equivalent, and both time2posix and posix2time degenerate
71 to the identity function.
74 difftime(3), localtime(3), mktime(3), time(2)