1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1999-08-14 07:59:58 +00:00
|
|
|
.\"
|
2005-09-11 17:09:50 +00:00
|
|
|
.Dd September 11, 2005
|
1996-05-01 23:17:27 +00:00
|
|
|
.Dt TIME2POSIX 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm time2posix ,
|
|
|
|
.Nm posix2time
|
|
|
|
.Nd convert seconds since the Epoch
|
2000-04-21 09:42:15 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1996-05-01 23:17:27 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In time.h
|
1996-05-01 23:17:27 +00:00
|
|
|
.Ft time_t
|
2005-09-11 17:09:50 +00:00
|
|
|
.Fn time2posix "time_t t"
|
1996-05-01 23:17:27 +00:00
|
|
|
.Ft time_t
|
2005-09-11 17:09:50 +00:00
|
|
|
.Fn posix2time "time_t t"
|
1996-05-01 23:17:27 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.St -p1003.1-88
|
1994-09-13 03:39:01 +00:00
|
|
|
legislates that a time_t value of
|
|
|
|
536457599 shall correspond to "Wed Dec 31 23:59:59 GMT 1986."
|
|
|
|
This effectively implies that POSIX time_t's cannot include leap
|
|
|
|
seconds and,
|
|
|
|
therefore,
|
|
|
|
that the system time must be adjusted as each leap occurs.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
1994-09-13 03:39:01 +00:00
|
|
|
If the time package is configured with leap-second support
|
|
|
|
enabled,
|
|
|
|
however,
|
|
|
|
no such adjustment is needed and
|
|
|
|
time_t values continue to increase over leap events
|
|
|
|
(as a true `seconds since...' value).
|
|
|
|
This means that these values will differ from those required by POSIX
|
|
|
|
by the net number of leap seconds inserted since the Epoch.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
1994-09-13 03:39:01 +00:00
|
|
|
Typically this is not a problem as the type time_t is intended
|
|
|
|
to be
|
|
|
|
(mostly)
|
|
|
|
opaque\(emtime_t values should only be obtained-from and
|
|
|
|
passed-to functions such as
|
1999-08-14 07:57:52 +00:00
|
|
|
.Xr time 3 ,
|
1996-05-01 23:17:27 +00:00
|
|
|
.Xr localtime 3 ,
|
|
|
|
.Xr mktime 3
|
1994-09-13 03:39:01 +00:00
|
|
|
and
|
1996-05-01 23:17:27 +00:00
|
|
|
.Xr difftime 3 .
|
1994-09-13 03:39:01 +00:00
|
|
|
However,
|
1999-06-07 03:59:56 +00:00
|
|
|
.St -p1003.1-88
|
1996-05-01 23:17:27 +00:00
|
|
|
gives an arithmetic
|
1994-09-13 03:39:01 +00:00
|
|
|
expression for directly computing a time_t value from a given date/time,
|
|
|
|
and the same relationship is assumed by some
|
|
|
|
(usually older)
|
|
|
|
applications.
|
|
|
|
Any programs creating/dissecting time_t's
|
|
|
|
using such a relationship will typically not handle intervals
|
|
|
|
over leap seconds correctly.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
1994-09-13 03:39:01 +00:00
|
|
|
The
|
1996-05-01 23:17:27 +00:00
|
|
|
.Fn time2posix
|
1994-09-13 03:39:01 +00:00
|
|
|
and
|
1996-05-01 23:17:27 +00:00
|
|
|
.Fn posix2time
|
1994-09-13 03:39:01 +00:00
|
|
|
functions are provided to address this time_t mismatch by converting
|
|
|
|
between local time_t values and their POSIX equivalents.
|
|
|
|
This is done by accounting for the number of time-base changes that
|
|
|
|
would have taken place on a POSIX system as leap seconds were inserted
|
|
|
|
or deleted.
|
|
|
|
These converted values can then be used in lieu of correcting the older
|
|
|
|
applications,
|
|
|
|
or when communicating with POSIX-compliant systems.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn time2posix
|
|
|
|
function is single-valued.
|
1994-09-13 03:39:01 +00:00
|
|
|
That is,
|
|
|
|
every local time_t
|
|
|
|
corresponds to a single POSIX time_t.
|
1996-05-01 23:17:27 +00:00
|
|
|
The
|
|
|
|
.Fn posix2time
|
|
|
|
function is less well-behaved:
|
1994-09-13 03:39:01 +00:00
|
|
|
for a positive leap second hit the result is not unique,
|
|
|
|
and for a negative leap second hit the corresponding
|
2005-02-13 22:25:33 +00:00
|
|
|
POSIX time_t does not exist so an adjacent value is returned.
|
1994-09-13 03:39:01 +00:00
|
|
|
Both of these are good indicators of the inferiority of the
|
|
|
|
POSIX representation.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
1997-05-19 16:33:27 +00:00
|
|
|
The following table summarizes the relationship between time_t
|
|
|
|
and its conversion to,
|
1994-09-13 03:39:01 +00:00
|
|
|
and back from,
|
|
|
|
the POSIX representation over the leap second inserted at the end of June,
|
|
|
|
1993.
|
2000-11-10 17:46:15 +00:00
|
|
|
.Bl -column "93/06/30" "23:59:59" "A+0" "X=time2posix(T)"
|
2000-12-29 14:08:20 +00:00
|
|
|
.It Sy "DATE TIME T X=time2posix(T) posix2time(X)"
|
|
|
|
.It "93/06/30 23:59:59 A+0 B+0 A+0"
|
|
|
|
.It "93/06/30 23:59:60 A+1 B+1 A+1 or A+2"
|
|
|
|
.It "93/07/01 00:00:00 A+2 B+1 A+1 or A+2"
|
|
|
|
.It "93/07/01 00:00:01 A+3 B+2 A+3"
|
2000-11-10 17:46:15 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
1994-09-13 03:39:01 +00:00
|
|
|
A leap second deletion would look like...
|
2000-11-10 17:46:15 +00:00
|
|
|
.Bl -column "??/06/30" "23:59:58" "A+0" "X=time2posix(T)"
|
2000-12-29 14:08:20 +00:00
|
|
|
.It Sy "DATE TIME T X=time2posix(T) posix2time(X)"
|
|
|
|
.It "??/06/30 23:59:58 A+0 B+0 A+0"
|
|
|
|
.It "??/07/01 00:00:00 A+1 B+2 A+1"
|
|
|
|
.It "??/07/01 00:00:01 A+2 B+3 A+2"
|
2000-11-10 17:46:15 +00:00
|
|
|
.El
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
2000-11-10 17:46:15 +00:00
|
|
|
.D1 No "[Note: posix2time(B+1) => A+0 or A+1]"
|
1996-05-01 23:17:27 +00:00
|
|
|
.Pp
|
1994-09-13 03:39:01 +00:00
|
|
|
If leap-second support is not enabled,
|
|
|
|
local time_t's and
|
|
|
|
POSIX time_t's are equivalent,
|
|
|
|
and both
|
1996-05-01 23:17:27 +00:00
|
|
|
.Fn time2posix
|
1994-09-13 03:39:01 +00:00
|
|
|
and
|
1996-05-01 23:17:27 +00:00
|
|
|
.Fn posix2time
|
1994-09-13 03:39:01 +00:00
|
|
|
degenerate to the identity function.
|
1996-05-01 23:17:27 +00:00
|
|
|
.Sh "SEE ALSO"
|
|
|
|
.Xr difftime 3 ,
|
|
|
|
.Xr localtime 3 ,
|
|
|
|
.Xr mktime 3 ,
|
|
|
|
.Xr time 3
|
2009-05-23 06:31:50 +00:00
|
|
|
.\" @(#)time2posix.3 8.1
|
|
|
|
.\" This file is in the public domain, so clarified as of
|
|
|
|
.\" 1996-06-05 by Arthur David Olson.
|