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