1.\" $MirOS: src/lib/libc/time/tzset.3,v 1.5 2011/11/20 19:32:10 tg Exp $
2.\" $OpenBSD: tzset.3,v 1.14 2004/04/16 10:48:39 jmc Exp $
3.Dd May 24, 1999
4.Dt TZSET 3
5.Os
6.Sh NAME
7.Nm tzset
8.Nd initialize time conversion information
9.Sh SYNOPSIS
10.Fd #include <time.h>
11.Ft void
12.Fn tzset "void"
13.Sh DESCRIPTION
14.Fn tzset
15uses the value of the environment variable
16.Ev TZ
17to set time conversion information used by
18.Xr localtime 3 .
19If
20.Ev TZ
21does not appear in the environment,
22the best available approximation to local wall clock time, as specified
23by the
24.Xr tzfile 5
25format file
26.Em localtime
27in the system time conversion information directory, is used by
28.Xr localtime 3 .
29.Pp
30If
31.Ev TZ
32appears in the environment but its value is a null string,
33Coordinated Universal Time (UTC) is used.
34.Pp
35As a side effect, calling
36.Fn tzset
37also initialises the leap second table for the
38.Xr mirtime 3
39function suite.
40.Pp
41If
42.Ev TZ
43appears in the environment and its value begins with a colon,
44it is used as a pathname of a file
45from which to read the time conversion information.
46.Pp
47If
48.Ev TZ
49appears in the environment and its value does not begin with a colon,
50it is first used as the
51pathname of a file from which to read the time conversion information,
52and, if that file cannot be read, is used directly as a specification of
53the time conversion information.
54.Pp
55When
56.Ev TZ
57is used as a pathname, if it begins with a slash,
58it is used as an absolute pathname; otherwise,
59it is used as a pathname relative to a system time conversion information
60directory.
61The file must be in the format specified in
62.Xr tzfile 5 .
63.Pp
64When
65.Ev TZ
66is used directly as a specification of the time conversion information,
67it must have the following syntax (spaces inserted for clarity):
68.Bd -ragged -offset indent
69.Ar std
70.Ar offset
71.Op Ar dst Op Ar offset
72.Op , Ar rule
73.Ed
74.Pp
75Where:
76.Bl -tag -width "std and dst"
77.It Ar std No and Ar dst
78Three or more bytes that are the designation for the standard
79.Pq Ar std
80or summer
81.Pq Ar dst
82time zone.
83Only
84.Ar std
85is required; if
86.Ar dst
87is missing, then summer time does not apply in this locale.
88Upper and lowercase letters are explicitly allowed.
89Any characters except a leading colon
90.Pq Sq \&: ,
91digits, comma
92.Pq Sq \&, ,
93minus
94.Pq Sq \&- ,
95plus
96.Pq Sq \&+ ,
97and
98.Tn ASCII
99.Tn NUL
100are allowed.
101.It Ar offset
102Indicates the value one must add to the local time to arrive at
103Coordinated Universal Time.
104.Ar offset
105has the form
106.Pq spaces inserted for clarity :
107.Bd -ragged -offset indent
108.Ar hh
109.Op : Ar mm Op : Ar ss
110.Ed
111.Pp
112The minutes
113.Pq Ar mm
114and seconds
115.Pq Ar ss
116are optional.
117The hour
118.Pq Ar hh
119is required and may be a single digit.
120The
121.Ar offset
122following
123.Ar std
124is required.
125If no
126.Ar offset
127follows
128.Ar dst ,
129summer time is assumed to be one hour ahead of standard time.
130One or more digits may be used; the value is always interpreted as a
131decimal number.
132The hour must be between zero and 24, and the minutes (and
133seconds) -- if present -- between zero and 59.
134If preceded by a
135.Dq \&- ,
136the time zone shall be east of the Prime Meridian; otherwise it shall be
137west (which may be indicated by an optional preceding
138.Dq \&+ ) .
139.It Ar rule
140Indicates when to change to and back from summer time.
141.Ar rule
142has the form (spaces added for clarity):
143.Bd -ragged -offset indent
144.Ar date
145/
146.Ar time ,
147.Ar date
148/
149.Ar time
150.Ed
151.Pp
152where the first
153.Ar date
154describes when the change from standard to summer time occurs and the
155second
156.Ar date
157describes when the change back happens.
158Each
159.Ar time
160field describes when, in current local time, the change to the other
161time is made.
162.Pp
163The format of
164.Ar date
165is one of the following (spaces added for clarity):
166.Bl -tag -width "M m . n . d"
167.It J Ar n
168The Julian day
169.Ar n
170.Po
1711 \&<\&=
172.Ar n
173\&<\&= 365
174.Pc .
175Leap days are not counted; that is, in all years -- including leap
176years -- February 28 is day 59 and March 1 is day 60.
177It is impossible to explicitly refer to the occasional February 29.
178.It Ar n
179The zero-based Julian day
180.Po
1810 \&<\&=
182.Ar n
183\&<\&= 365
184.Pc .
185Leap days are counted, and it is possible to refer to February 29.
186.It Xo M Ar m No . Ar n
187.No . Ar d
188.Xc
189Day
190.Ar d
191.Po
1921 \&<\&=
193.Ar d
194\&<\&= 6
195.Pc
196of week
197.Ar n
198.Po
1991 \&<\&=
200.Ar n
201\&<\&= 5
202.Pc
203of month
204.Ar m
205.Po
2061 \&<\&=
207.Ar m
208\&<\&= 12
209.Pc ,
210where week 5 means
211.Do
212the last
213.Ar d
214day in month
215.Ar m
216.Dc
217which may occur in either the fourth or the fifth week.
218Week 1 is the first week in which the
219.Ar d Ns th
220day occurs.
221Day zero is Sunday.
222.El
223.Pp
224The
225.Ar time
226has the same format as
227.Ar offset
228except that no leading sign
229.Po
230.Dq \&-
231or
232.Dq \&+
233.Pc
234is allowed.
235The default, if
236.Ar time
237is not given, is
238.Cm 02:00:00 .
239.El
240.Pp
241If no
242.Ar rule
243is present in
244.Ev TZ ,
245the rules specified
246by the
247.Xr tzfile 5
248format
249file
250.Cm posixrules
251in the system time conversion information directory are used, with the
252standard and summer time offsets from UTC replaced by those specified by
253the
254.Ar offset
255values in
256.Ev TZ .
257.Pp
258For compatibility with System V Release 3.1, a semicolon
259.Pq Sq \&;
260may be used to separate the
261.Ar rule
262from the rest of the specification.
263.Pp
264If the
265.Ev TZ
266environment variable does not specify a
267.Xr tzfile 5
268format file
269and cannot be interpreted as a direct specification,
270UTC is used.
271.Sh FILES
272.Bl -tag -width "/usr/share/zoneinfo/posixrules" -compact
273.It Pa /usr/share/zoneinfo
274time zone information directory
275.It Pa /etc/localtime
276local time zone file
277.It Pa /usr/share/zoneinfo/posixrules
278used with POSIX-style
279.Ev TZ Ns s
280.It Pa /usr/share/zoneinfo/UTC
281for UTC leap seconds
282.El
283.Pp
284If
285.Pa /usr/share/zoneinfo/UTC
286is absent,
287UTC leap seconds are loaded from
288.Pa /usr/share/zoneinfo/posixrules .
289.Sh SEE ALSO
290.Xr ctime 3 ,
291.Xr getenv 3 ,
292.Xr mirtime 3 ,
293.Xr strftime 3 ,
294.Xr time 3 ,
295.Xr tzfile 5
296.\" @(#)newtzset.3	7.5
297.\" This file is in the public domain, so clarified as of
298.\" 2003-02-14 by Arthur David Olson (arthur_david_olson@nih.gov).
299