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