xref: /freebsd/lib/libc/stdtime/tzset.3 (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
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 December 25, 2023
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 to
62local 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
72.Pq Tn UTC
73is used (without leap second correction).
74.Pp
75If
76.Ev TZ
77appears in the environment and its value begins with a colon
78.Pq Ql \&: ,
79the rest of its value is used as a pathname of a
80.Xr tzfile 5 Ns -format
81file from which to read the time conversion information.
82If the first character of the pathname is a slash
83.Pq Ql /
84it is used as
85an absolute pathname; otherwise, it is used as a pathname relative to
86the system time conversion information directory.
87.Pp
88If its value does not begin with a colon, it is first used as the pathname
89of a file (as described above) from which to read the time conversion
90information.
91If that file cannot be read, the value is then interpreted as a direct
92specification (the format is described below) of the time conversion
93information.
94.Pp
95If the
96.Ev TZ
97environment variable does not specify a
98.Xr tzfile 5 Ns -format
99file and cannot be interpreted as a direct specification,
100.Tn UTC
101is used.
102.Pp
103After the first call to
104.Nm tzset ,
105the
106.Vt timezone
107variable is set to the difference, in seconds, between Coordinated Universal
108Time (UTC) and the local time.
109The
110.Vt daylight
111variable is set to 0 if the local timezone is observing standard time.
112It is set to 1 if the local timezone ever observes an alternate time, such as summer time.
113The first element of the
114.Vt tzname
115array is the timezone name of standard time, while the second element is the
116name of the altnerative time zone.
117.Sh SPECIFICATION FORMAT
118When
119.Ev TZ
120is used directly as a specification of the time conversion information,
121it must have the following syntax (spaces inserted for clarity):
122.Bd -ragged -offset indent
123.Em std offset
124.Bo
125.Em dst
126.Bq Em offset
127.Bq , Em rule
128.Bc
129.Ed
130.Pp
131Where:
132.Bl -tag -width std_and_dst -offset indent
133.It Em std No and Em dst
134Three or more bytes that are the designation for the standard
135.Pq Em std
136or summer
137.Pq Em dst
138time zone.
139Only
140.Em std
141is required; if
142.Em dst
143is missing, then summer time does not apply in this locale.
144Upper and lowercase letters are explicitly allowed.
145Any characters
146except a leading colon
147.Pq Ql \&: ,
148digits, comma
149.Pq Ql \&, ,
150minus
151.Pq Ql \- ,
152plus
153.Pq Ql + ,
154and
155.Tn ASCII
156.Dv NUL
157are allowed.
158.It Em offset
159Indicates the value one must add to the local time to arrive at
160Coordinated Universal Time.
161The
162.Em offset
163has the form:
164.Bd -ragged -offset indent
165.Sm off
166.Em hh Bo
167.Em : mm
168.Bq Em : ss
169.Bc
170.Sm on
171.Ed
172.Pp
173The minutes
174.Pq Em mm
175and seconds
176.Pq Em ss
177are optional.
178The hour
179.Pq Em hh
180is required and may be a single digit.
181The
182.Em offset
183following
184.Em std
185is required.
186If no
187.Em offset
188follows
189.Em dst ,
190summer time is assumed to be one hour ahead of standard time.
191One or
192more digits may be used; the value is always interpreted as a decimal
193number.
194The hour must be between zero and 24, and the minutes (and
195seconds) \(em if present \(em between zero and 59.
196If preceded by a
197.Pq Ql \-
198the time zone shall be east of the Prime Meridian; otherwise it shall be
199west (which may be indicated by an optional preceding
200.Pq Ql + ) .
201.It Em rule
202Indicates when to change to and back from summer time.
203The
204.Em rule
205has the form:
206.Bd -ragged -offset indent
207.Em date/time,date/time
208.Ed
209.Pp
210where the first
211.Em date
212describes when the change from standard to summer time occurs and the
213second
214.Em date
215describes when the change back happens.
216Each
217.Em time
218field describes when, in current local time, the change to the other
219time is made.
220.Pp
221The format of
222.Em date
223is one of the following:
224.Bl -tag -width "M.m.n.d"
225.It Sy J Em n
226The Julian day
227.Em n
228(1 \*(Le
229.Em n
230\*(Le 365).
231Leap days are not counted; that is, in all years \(em including leap
232years \(em February 28 is day 59 and March 1 is day 60.
233It is
234impossible to explicitly refer to the occasional February 29.
235.It Em n
236The zero-based Julian day
237(0 \*(Le
238.Em n
239\*(Le 365 ) .
240Leap days are counted, and it is possible to refer to February 29.
241.It Sy M Em m.n.d
242The
243.Em d Ns 'th
244day (0 \*(Le
245.Em d
246\*(Le 6)
247of week
248.Em n
249of month
250.Em m
251of the year
252(1 \*(Le
253.Em n
254\*(Le 5),
255(1 \*(Le
256.Em m
257\*(Le 12),
258where week 5 means
259.Do
260the last
261.Em d
262day in month
263.Em m
264.Dc
265which may occur in either the fourth or the fifth week).
266Week 1 is the
267first week in which the
268.Em d Ns 'th
269day occurs.
270Day zero is Sunday.
271.Pp
272The
273.Em time
274has the same format as
275.Em offset
276except that no leading sign
277.Pq Ql \-
278or
279.Pq Ql +
280is allowed.
281The default, if
282.Em time
283is not given, is
284.Sy 02:00:00 .
285.El
286.Pp
287If no
288.Em rule
289is present in the
290.Ev TZ
291specification, the rules specified
292by the
293.Xr tzfile 5 Ns -format
294file
295.Em posixrules
296in the system time conversion information directory are used, with the
297standard and summer time offsets from
298.Tn UTC
299replaced by those specified by
300the
301.Em offset
302values in
303.Ev TZ .
304.El
305.Pp
306For compatibility with System V Release 3.1, a semicolon
307.Pq Ql \&;
308may be used to separate the
309.Em rule
310from the rest of the specification.
311.Sh FILES
312.Bl -tag -width /usr/share/zoneinfo/posixrules -compact
313.It Pa /etc/localtime
314local time zone file
315.It Pa /usr/share/zoneinfo
316time zone directory
317.It Pa /usr/share/zoneinfo/posixrules
318rules for
319.Tn POSIX Ns -style
320.Tn TZ Ns 's
321.It Pa /usr/share/zoneinfo/Etc/GMT
322for
323.Tn UTC
324leap seconds
325.El
326.Pp
327If the file
328.Pa /usr/share/zoneinfo/UTC
329does not exist,
330.Tn UTC
331leap seconds are loaded from
332.Pa /usr/share/zoneinfo/posixrules .
333.Sh SEE ALSO
334.Xr date 1 ,
335.Xr gettimeofday 2 ,
336.Xr ctime 3 ,
337.Xr getenv 3 ,
338.Xr time 3 ,
339.Xr tzfile 5
340.Sh HISTORY
341The
342.Fn tzset
343function first appeared in
344.Bx 4.4 .
345