xref: /freebsd/lib/libc/stdtime/tzset.3 (revision acd546f01e58354af049455472980c6c4a52e18b)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Arthur Olson.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd September 30, 2025
32.Dt TZSET 3
33.Os
34.Sh NAME
35.Nm daylight ,
36.Nm timezone ,
37.Nm tzname ,
38.Nm tzset
39.Nd initialize time conversion information
40.Sh LIBRARY
41.Lb libc
42.Sh SYNOPSIS
43.In time.h
44.Vt extern int daylight ;
45.Vt extern long timezone ;
46.Vt extern char *tzname[2] ;
47.Ft void
48.Fn tzset void
49.Sh DESCRIPTION
50The
51.Fn tzset
52function
53initializes time conversion information used by the library routine
54.Xr localtime 3 .
55The environment variable
56.Ev TZ
57specifies how this is done.
58.Pp
59If
60.Ev TZ
61does not appear in the environment, the best available approximation
62to local wall clock time, as specified by the
63.Xr tzfile 5 Ns -format
64file
65.Pa /etc/localtime
66is used.
67.Pp
68If
69.Ev TZ
70appears in the environment but its value is a null string, Coordinated
71Universal Time (UTC) is used (without leap second correction).
72.Pp
73If
74.Ev TZ
75appears in the environment and its value begins with a colon
76.Pq Ql \&: ,
77the rest of its value is used as a pathname of a
78.Xr tzfile 5 Ns -format
79file from which to read the time conversion information.
80If the first character of the pathname is a slash
81.Pq Ql /
82it is used as an absolute pathname; otherwise, it is used as a
83pathname relative to the system time conversion information directory.
84.Pp
85If its value does not begin with a colon, it is first used as the
86pathname of a file (as described above) from which to read the time
87conversion information.
88If that file cannot be read, the value is then interpreted as a direct
89specification (the format is described below) of the time conversion
90information.
91.Pp
92If the
93.Ev TZ
94environment variable does not specify a
95.Xr tzfile 5 Ns -format
96file and cannot be interpreted as a direct specification, UTC is used.
97.Pp
98After the first call to
99.Nm tzset ,
100the
101.Vt timezone
102variable is set to the difference, in seconds, between Coordinated
103Universal Time (UTC) and the local time.
104The
105.Vt daylight
106variable is set to 0 if the local timezone is observing standard time.
107It is set to 1 if the local timezone ever observes an alternate time,
108such as summer time.
109The first element of the
110.Vt tzname
111array is the timezone name of standard time, while the second element
112is the name of the altnerative time zone.
113.Sh SPECIFICATION FORMAT
114When
115.Ev TZ
116is used directly as a specification of the time conversion information,
117it must have the following syntax (spaces inserted for clarity):
118.Bd -ragged -offset indent
119.Em std offset
120.Bo
121.Em dst
122.Bq Em offset
123.Bq , Em rule
124.Bc
125.Ed
126.Pp
127Where:
128.Bl -tag -width std_and_dst -offset indent
129.It Em std No and Em dst
130Three or more bytes that are the designation for the standard
131.Pq Em std
132or summer
133.Pq Em dst
134time zone.
135Only
136.Em std
137is required; if
138.Em dst
139is missing, then summer time does not apply in this locale.
140Upper and lowercase letters are explicitly allowed.
141Any characters
142except a leading colon
143.Pq Ql \&: ,
144digits, comma
145.Pq Ql \&, ,
146minus
147.Pq Ql \- ,
148plus
149.Pq Ql + ,
150and ASCII
151.Dv NUL
152are allowed.
153.It Em offset
154Indicates the value one must add to the local time to arrive at
155Coordinated Universal Time.
156The
157.Em offset
158has the form:
159.Bd -ragged -offset indent
160.Sm off
161.Em hh Bo
162.Em : mm
163.Bq Em : ss
164.Bc
165.Sm on
166.Ed
167.Pp
168The minutes
169.Pq Em mm
170and seconds
171.Pq Em ss
172are optional.
173The hour
174.Pq Em hh
175is required and may be a single digit.
176The
177.Em offset
178following
179.Em std
180is required.
181If no
182.Em offset
183follows
184.Em dst ,
185summer time is assumed to be one hour ahead of standard time.
186One or
187more digits may be used; the value is always interpreted as a decimal
188number.
189The hour must be between zero and 24, and the minutes (and
190seconds) \(em if present \(em between zero and 59.
191If preceded by a
192.Pq Ql \-
193the time zone shall be east of the Prime Meridian; otherwise it shall be
194west (which may be indicated by an optional preceding
195.Pq Ql + ) .
196.It Em rule
197Indicates when to change to and back from summer time.
198The
199.Em rule
200has the form:
201.Bd -ragged -offset indent
202.Em date/time,date/time
203.Ed
204.Pp
205where the first
206.Em date
207describes when the change from standard to summer time occurs and the
208second
209.Em date
210describes when the change back happens.
211Each
212.Em time
213field describes when, in current local time, the change to the other
214time is made.
215.Pp
216The format of
217.Em date
218is one of the following:
219.Bl -tag -width "M.m.n.d"
220.It Sy J Em n
221The Julian day
222.Em n
223(1 \*(Le
224.Em n
225\*(Le 365).
226Leap days are not counted; that is, in all years \(em including leap
227years \(em February 28 is day 59 and March 1 is day 60.
228It is
229impossible to explicitly refer to the occasional February 29.
230.It Em n
231The zero-based Julian day
232(0 \*(Le
233.Em n
234\*(Le 365 ) .
235Leap days are counted, and it is possible to refer to February 29.
236.It Sy M Em m.n.d
237The
238.Em d Ns 'th
239day (0 \*(Le
240.Em d
241\*(Le 6)
242of week
243.Em n
244of month
245.Em m
246of the year
247(1 \*(Le
248.Em n
249\*(Le 5),
250(1 \*(Le
251.Em m
252\*(Le 12),
253where week 5 means
254.Do
255the last
256.Em d
257day in month
258.Em m
259.Dc
260which may occur in either the fourth or the fifth week).
261Week 1 is the
262first week in which the
263.Em d Ns 'th
264day occurs.
265Day zero is Sunday.
266.Pp
267The
268.Em time
269has the same format as
270.Em offset
271except that no leading sign
272.Pq Ql \-
273or
274.Pq Ql +
275is allowed.
276The default, if
277.Em time
278is not given, is
279.Sy 02:00:00 .
280.El
281.Pp
282If no
283.Em rule
284is present in the
285.Ev TZ
286specification, the rules specified
287by the
288.Xr tzfile 5 Ns -format
289file
290.Em posixrules
291in the system time conversion information directory are used, with the
292standard and summer time offsets from UTC replaced by those specified
293by the
294.Em offset
295values in
296.Ev TZ .
297.El
298.Pp
299For compatibility with System V Release 3.1, a semicolon
300.Pq Ql \&;
301may be used to separate the
302.Em rule
303from the rest of the specification.
304.Sh FILES
305.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
306.It Pa /etc/localtime
307local time zone file
308.It Pa /usr/share/zoneinfo
309time zone directory
310.It Pa /usr/share/zoneinfo/posixrules
311rules for POSIX-style TZs
312.It Pa /usr/share/zoneinfo/Etc/GMT
313for UTC leap seconds
314.El
315.Pp
316If the file
317.Pa /usr/share/zoneinfo/UTC
318does not exist, UTC leap seconds are loaded from
319.Pa /usr/share/zoneinfo/posixrules .
320.Sh SEE ALSO
321.Xr date 1 ,
322.Xr gettimeofday 2 ,
323.Xr ctime 3 ,
324.Xr getenv 3 ,
325.Xr time 3 ,
326.Xr tzfile 5
327.Sh HISTORY
328The
329.Fn tzset
330function first appeared in
331.Bx 4.4 .
332