time2posix.3 3.4 KB

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