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