newtzset.3 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. .\" This file is in the public domain, so clarified as of
  2. .\" 2009-05-17 by Arthur David Olson.
  3. .TH newtzset 3 "" "Time Zone Database"
  4. .SH NAME
  5. tzset \- initialize time conversion information
  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 timezone_t tzalloc(char const *TZ);
  13. .PP
  14. .B void tzfree(timezone_t tz);
  15. .PP
  16. .B void tzset(void);
  17. .PP
  18. .B cc ... \*-ltz
  19. .fi
  20. .SH DESCRIPTION
  21. .ie '\(en'' .ds en \-
  22. .el .ds en \(en
  23. .ie '\(lq'' .ds lq \&"\"
  24. .el .ds lq \(lq\"
  25. .ie '\(rq'' .ds rq \&"\"
  26. .el .ds rq \(rq\"
  27. .de q
  28. \\$3\*(lq\\$1\*(rq\\$2
  29. ..
  30. The
  31. .B tzalloc
  32. function
  33. allocates and returns a timezone object described by
  34. .BR TZ .
  35. If
  36. .B TZ
  37. is not a valid timezone description, or if the object cannot be allocated,
  38. .B tzalloc
  39. returns a null pointer and sets
  40. .BR errno .
  41. .PP
  42. The
  43. .B tzfree
  44. function
  45. frees a timezone object
  46. .BR tz ,
  47. which should have been successfully allocated by
  48. .BR tzalloc .
  49. This invalidates any
  50. .B tm_zone
  51. pointers that
  52. .B tz
  53. was used to set.
  54. .PP
  55. The
  56. .B tzset
  57. function
  58. acts like
  59. .BR tzalloc(getenv("TZ")) ,
  60. except it saves any resulting timezone object into internal
  61. storage that is accessed by
  62. .BR localtime ,
  63. .BR localtime_r ,
  64. and
  65. .BR mktime .
  66. The anonymous shared timezone object is freed by the next call to
  67. .BR tzset .
  68. If the implied call to
  69. .B tzalloc
  70. fails,
  71. .B tzset
  72. falls back on Universal Time (UT).
  73. .PP
  74. If
  75. .B TZ
  76. is null, the best available approximation to local (wall
  77. clock) time, as specified by the
  78. .BR tzfile (5)-format
  79. file
  80. .B localtime
  81. in the system time conversion information directory, is used.
  82. If
  83. .B TZ
  84. is the empty string,
  85. UT is used, with the abbreviation "UTC"
  86. and without leap second correction; please see
  87. .BR newctime (3)
  88. for more about UT, UTC, and leap seconds. If
  89. .B TZ
  90. is nonnull and nonempty:
  91. .IP
  92. if the value begins with a colon, it is used as a pathname of a file
  93. from which to read the time conversion information;
  94. .IP
  95. if the value does not begin with a colon, it is first used as the
  96. pathname of a file from which to read the time conversion information,
  97. and, if that file cannot be read, is used directly as a specification of
  98. the time conversion information.
  99. .PP
  100. When
  101. .B TZ
  102. is used as a pathname, if it begins with a slash,
  103. it is used as an absolute pathname; otherwise,
  104. it is used as a pathname relative to a system time conversion information
  105. directory.
  106. The file must be in the format specified in
  107. .BR tzfile (5).
  108. .PP
  109. When
  110. .B TZ
  111. is used directly as a specification of the time conversion information,
  112. it must have the following syntax (spaces inserted for clarity):
  113. .IP
  114. \fIstd\|offset\fR[\fIdst\fR[\fIoffset\fR][\fB,\fIrule\fR]]
  115. .PP
  116. Where:
  117. .RS
  118. .TP 15
  119. .IR std " and " dst
  120. Three or more bytes that are the designation for the standard
  121. .RI ( std )
  122. or the alternative
  123. .RI ( dst ,
  124. such as daylight saving time)
  125. time zone. Only
  126. .I std
  127. is required; if
  128. .I dst
  129. is missing, then daylight saving time does not apply in this locale.
  130. Upper- and lowercase letters are explicitly allowed. Any characters
  131. except a leading colon
  132. .RB ( : ),
  133. digits, comma
  134. .RB ( , ),
  135. ASCII minus
  136. .RB ( \*- ),
  137. ASCII plus
  138. .RB ( + ),
  139. and NUL bytes are allowed.
  140. Alternatively, a designation can be surrounded by angle brackets
  141. .B <
  142. and
  143. .BR > ;
  144. in this case, the designation can contain any characters other than
  145. .B >
  146. and NUL.
  147. .TP
  148. .I offset
  149. Indicates the value one must add to the local time to arrive at
  150. Coordinated Universal Time. The
  151. .I offset
  152. has the form:
  153. .RS
  154. .IP
  155. \fIhh\fR[\fB:\fImm\fR[\fB:\fIss\fR]]
  156. .RE
  157. .IP
  158. The minutes
  159. .RI ( mm )
  160. and seconds
  161. .RI ( ss )
  162. are optional. The hour
  163. .RI ( hh )
  164. is required and may be a single digit. The
  165. .I offset
  166. following
  167. .I std
  168. is required. If no
  169. .I offset
  170. follows
  171. .IR dst ,
  172. daylight saving time is assumed to be one hour ahead of standard time. One or
  173. more digits may be used; the value is always interpreted as a decimal
  174. number. The hour must be between zero and 24, and the minutes (and
  175. seconds) \*(en if present \*(en between zero and 59. If preceded by a
  176. .q "\*-" ,
  177. the time zone shall be east of the Prime Meridian; otherwise it shall be
  178. west (which may be indicated by an optional preceding
  179. .q "+" .
  180. .TP
  181. .I rule
  182. Indicates when to change to and back from daylight saving time. The
  183. .I rule
  184. has the form:
  185. .RS
  186. .IP
  187. \fIdate\fB/\fItime\fB,\fIdate\fB/\fItime\fR
  188. .RE
  189. .IP
  190. where the first
  191. .I date
  192. describes when the change from standard to daylight saving time occurs and the
  193. second
  194. .I date
  195. describes when the change back happens. Each
  196. .I time
  197. field describes when, in current local time, the change to the other
  198. time is made.
  199. As an extension to POSIX, daylight saving is assumed to be in effect
  200. all year if it begins January 1 at 00:00 and ends December 31 at
  201. 24:00 plus the difference between daylight saving and standard time,
  202. leaving no room for standard time in the calendar.
  203. .IP
  204. The format of
  205. .I date
  206. is one of the following:
  207. .RS
  208. .TP 10
  209. .BI J n
  210. The Julian day
  211. .I n
  212. .RI "(1\ \(<=" "\ n\ " "\(<=\ 365).
  213. Leap days are not counted; that is, in all years \*(en including leap
  214. years \*(en February 28 is day 59 and March 1 is day 60. It is
  215. impossible to explicitly refer to the occasional February 29.
  216. .TP
  217. .I n
  218. The zero-based Julian day
  219. .RI "(0\ \(<=" "\ n\ " "\(<=\ 365).
  220. Leap days are counted, and it is possible to refer to February 29.
  221. .TP
  222. .BI M m . n . d
  223. The
  224. .IR d' th
  225. day
  226. .RI "(0\ \(<=" "\ d\ " "\(<=\ 6)
  227. of week
  228. .I n
  229. of month
  230. .I m
  231. of the year
  232. .RI "(1\ \(<=" "\ n\ " "\(<=\ 5,
  233. .RI "1\ \(<=" "\ m\ " "\(<=\ 12,
  234. where week 5 means
  235. .q "the last \fId\fP day in month \fIm\fP"
  236. which may occur in either the fourth or the fifth week). Week 1 is the
  237. first week in which the
  238. .IR d' th
  239. day occurs. Day zero is Sunday.
  240. .RE
  241. .IP "" 15
  242. The
  243. .I time
  244. has the same format as
  245. .I offset
  246. except that POSIX does not allow a leading sign (\c
  247. .q "\*-"
  248. or
  249. .q "+" ).
  250. As an extension to POSIX, the hours part of
  251. .I time
  252. can range from \-167 through 167; this allows for unusual rules such
  253. as
  254. .q "the Saturday before the first Sunday of March" .
  255. The default, if
  256. .I time
  257. is not given, is
  258. .BR 02:00:00 .
  259. .RE
  260. .LP
  261. Here are some examples of
  262. .B TZ
  263. values that directly specify the timezone; they use some of the
  264. extensions to POSIX.
  265. .TP
  266. .B EST5
  267. stands for US Eastern Standard
  268. Time (EST), 5 hours behind UT, without daylight saving.
  269. .TP
  270. .B <+12>\*-12<+13>,M11.1.0,M1.2.1/147
  271. stands for Fiji time, 12 hours ahead
  272. of UT, springing forward on November's first Sunday at 02:00, and
  273. falling back on January's second Monday at 147:00 (i.e., 03:00 on the
  274. first Sunday on or after January 14). The abbreviations for standard
  275. and daylight saving time are
  276. .q "+12"
  277. and
  278. .q "+13".
  279. .TP
  280. .B IST\*-2IDT,M3.4.4/26,M10.5.0
  281. stands for Israel Standard Time (IST) and Israel Daylight Time (IDT),
  282. 2 hours ahead of UT, springing forward on March's fourth
  283. Thursday at 26:00 (i.e., 02:00 on the first Friday on or after March
  284. 23), and falling back on October's last Sunday at 02:00.
  285. .TP
  286. .B <\*-04>4<\*-03>,J1/0,J365/25
  287. stands for permanent daylight saving time, 3 hours behind UT with
  288. abbreviation
  289. .q "\*-03".
  290. There is a dummy fall-back transition on December 31 at 25:00 daylight
  291. saving time (i.e., 24:00 standard time, equivalent to January 1 at
  292. 00:00 standard time), and a simultaneous spring-forward transition on
  293. January 1 at 00:00 standard time, so daylight saving time is in effect
  294. all year and the initial
  295. .B <\*-04>
  296. is a placeholder.
  297. .TP
  298. .B <\*-03>3<\*-02>,M3.5.0/\*-2,M10.5.0/\*-1
  299. stands for time in western Greenland, 3 hours behind UT, where clocks
  300. follow the EU rules of
  301. springing forward on March's last Sunday at 01:00 UT (\-02:00 local
  302. time, i.e., 22:00 the previous day) and falling back on October's last
  303. Sunday at 01:00 UT (\-01:00 local time, i.e., 23:00 the previous day).
  304. The abbreviations for standard and daylight saving time are
  305. .q "\*-03"
  306. and
  307. .q "\*-02".
  308. .PP
  309. If no
  310. .I rule
  311. is present in
  312. .BR TZ ,
  313. the rules specified
  314. by the
  315. .BR tzfile (5)-format
  316. file
  317. .B posixrules
  318. in the system time conversion information directory are used, with the
  319. standard and daylight saving time offsets from UT replaced by those specified by
  320. the
  321. .I offset
  322. values in
  323. .BR TZ .
  324. .PP
  325. For compatibility with System V Release 3.1, a semicolon
  326. .RB ( ; )
  327. may be used to separate the
  328. .I rule
  329. from the rest of the specification.
  330. .SH FILES
  331. .ta \w'/usr/share/zoneinfo/posixrules\0\0'u
  332. /usr/share/zoneinfo timezone information directory
  333. .br
  334. /usr/share/zoneinfo/localtime local timezone file
  335. .br
  336. /usr/share/zoneinfo/posixrules default DST rules (obsolete,
  337. and can cause bugs if present)
  338. .br
  339. /usr/share/zoneinfo/GMT for UTC leap seconds
  340. .sp
  341. If
  342. .B /usr/share/zoneinfo/GMT
  343. is absent,
  344. UTC leap seconds are loaded from
  345. .BR /usr/share/zoneinfo/posixrules .
  346. .SH SEE ALSO
  347. getenv(3),
  348. newctime(3),
  349. newstrftime(3),
  350. time(2),
  351. tzfile(5)