14616d0f9Sopenharmony_cinewtzset(3)                Library Functions Manual                newtzset(3)
24616d0f9Sopenharmony_ci
34616d0f9Sopenharmony_ciNAME
44616d0f9Sopenharmony_ci       tzset - initialize time conversion information
54616d0f9Sopenharmony_ci
64616d0f9Sopenharmony_ciSYNOPSIS
74616d0f9Sopenharmony_ci       #include <time.h>
84616d0f9Sopenharmony_ci
94616d0f9Sopenharmony_ci       timezone_t tzalloc(char const *TZ);
104616d0f9Sopenharmony_ci
114616d0f9Sopenharmony_ci       void tzfree(timezone_t tz);
124616d0f9Sopenharmony_ci
134616d0f9Sopenharmony_ci       void tzset(void);
144616d0f9Sopenharmony_ci
154616d0f9Sopenharmony_ci       cc ... -ltz
164616d0f9Sopenharmony_ci
174616d0f9Sopenharmony_ciDESCRIPTION
184616d0f9Sopenharmony_ci       The tzalloc function allocates and returns a timezone object described
194616d0f9Sopenharmony_ci       by TZ.
204616d0f9Sopenharmony_ci
214616d0f9Sopenharmony_ci       If TZ is a null pointer, tzalloc uses the best available approximation
224616d0f9Sopenharmony_ci       to local (wall clock) time, as specified by the tzfile(5)-format file
234616d0f9Sopenharmony_ci       localtime in the system time conversion information directory.
244616d0f9Sopenharmony_ci
254616d0f9Sopenharmony_ci       If TZ is the empty string, tzalloc uses Universal Time (UT), with the
264616d0f9Sopenharmony_ci       abbreviation "UTC" and without leap second correction; please see
274616d0f9Sopenharmony_ci       newctime(3) for more about UT, UTC, and leap seconds.
284616d0f9Sopenharmony_ci
294616d0f9Sopenharmony_ci       If TZ is nonnull and nonempty:
304616d0f9Sopenharmony_ci
314616d0f9Sopenharmony_ci              if the value begins with a colon, it is used as a pathname of a
324616d0f9Sopenharmony_ci              file from which to read the time conversion information;
334616d0f9Sopenharmony_ci
344616d0f9Sopenharmony_ci              if the value does not begin with a colon, it is first used as
354616d0f9Sopenharmony_ci              the pathname of a file from which to read the time conversion
364616d0f9Sopenharmony_ci              information, and, if that file cannot be read, is used directly
374616d0f9Sopenharmony_ci              as a specification of the time conversion information.
384616d0f9Sopenharmony_ci
394616d0f9Sopenharmony_ci       When TZ contents are used as a pathname, a pathname beginning with "/"
404616d0f9Sopenharmony_ci       is used as-is; otherwise the pathname is relative to a system time
414616d0f9Sopenharmony_ci       conversion information directory.  The file must be in the format
424616d0f9Sopenharmony_ci       specified in tzfile(5).
434616d0f9Sopenharmony_ci
444616d0f9Sopenharmony_ci       When TZ is used directly as a specification of the time conversion
454616d0f9Sopenharmony_ci       information, it must have the following syntax:
464616d0f9Sopenharmony_ci
474616d0f9Sopenharmony_ci              stdoffset[dst[offset][,rule]]
484616d0f9Sopenharmony_ci
494616d0f9Sopenharmony_ci       Where:
504616d0f9Sopenharmony_ci
514616d0f9Sopenharmony_ci              std and dst
524616d0f9Sopenharmony_ci                     Three  or  more  bytes  that  are the designation for the
534616d0f9Sopenharmony_ci                     standard (std) or the alternative (dst, such as  daylight
544616d0f9Sopenharmony_ci                     saving  time) time zone.  Only std is required; if dst is
554616d0f9Sopenharmony_ci                     missing, then daylight saving time does not apply in this
564616d0f9Sopenharmony_ci                     locale.  Upper-  and  lowercase  letters  are  explicitly
574616d0f9Sopenharmony_ci                     allowed.   Any  characters  except  a  leading colon (:),
584616d0f9Sopenharmony_ci                     digits, comma (,), ASCII minus (-), ASCII plus  (+),  and
594616d0f9Sopenharmony_ci                     NUL  bytes are allowed.  Alternatively, a designation can
604616d0f9Sopenharmony_ci                     be surrounded by angle brackets < and >;  in  this  case,
614616d0f9Sopenharmony_ci                     the  designation  can contain any characters other than >
624616d0f9Sopenharmony_ci                     and NUL.
634616d0f9Sopenharmony_ci
644616d0f9Sopenharmony_ci              offset Indicates the value one must add to  the  local  time  to
654616d0f9Sopenharmony_ci                     arrive at Coordinated Universal Time.  The offset has the
664616d0f9Sopenharmony_ci                     form:
674616d0f9Sopenharmony_ci
684616d0f9Sopenharmony_ci                            hh[:mm[:ss]]
694616d0f9Sopenharmony_ci
704616d0f9Sopenharmony_ci                     The minutes (mm) and seconds (ss) are optional.  The hour
714616d0f9Sopenharmony_ci                     (hh)  is  required and may be a single digit.  The offset
724616d0f9Sopenharmony_ci                     following std is required.  If  no  offset  follows  dst,
734616d0f9Sopenharmony_ci                     daylight  saving  time is assumed to be one hour ahead of
744616d0f9Sopenharmony_ci                     standard time.  One or more digits may be used; the value
754616d0f9Sopenharmony_ci                     is always interpreted as a decimal number.  The hour must
764616d0f9Sopenharmony_ci                     be between zero and 24, and the minutes (and  seconds)  -
774616d0f9Sopenharmony_ci                     if  present - between zero and 59.  If preceded by a "-",
784616d0f9Sopenharmony_ci                     the time zone  shall  be  east  of  the  Prime  Meridian;
794616d0f9Sopenharmony_ci                     otherwise  it shall be west (which may be indicated by an
804616d0f9Sopenharmony_ci                     optional preceding "+".
814616d0f9Sopenharmony_ci
824616d0f9Sopenharmony_ci              rule   Indicates when to change to and back from daylight saving
834616d0f9Sopenharmony_ci                     time.  The rule has the form:
844616d0f9Sopenharmony_ci
854616d0f9Sopenharmony_ci                            date/time,date/time
864616d0f9Sopenharmony_ci
874616d0f9Sopenharmony_ci                     where the first  date  describes  when  the  change  from
884616d0f9Sopenharmony_ci                     standard  to  daylight  saving time occurs and the second
894616d0f9Sopenharmony_ci                     date describes when the change back happens.   Each  time
904616d0f9Sopenharmony_ci                     field  describes  when, in current local time, the change
914616d0f9Sopenharmony_ci                     to  the  other  time  is  made.   As  an   extension   to
924616d0f9Sopenharmony_ci                     POSIX.1-2017,  daylight saving is assumed to be in effect
934616d0f9Sopenharmony_ci                     all year if  it  begins  January  1  at  00:00  and  ends
944616d0f9Sopenharmony_ci                     December 31 at 24:00 plus the difference between daylight
954616d0f9Sopenharmony_ci                     saving  and  standard  time, leaving no room for standard
964616d0f9Sopenharmony_ci                     time in the calendar.
974616d0f9Sopenharmony_ci
984616d0f9Sopenharmony_ci                     The format of date is one of the following:
994616d0f9Sopenharmony_ci
1004616d0f9Sopenharmony_ci                     Jn     The Julian day n (1 <= n <= 365).  Leap  days  are
1014616d0f9Sopenharmony_ci                            not  counted;  that  is,  in all years - including
1024616d0f9Sopenharmony_ci                            leap years - February 28 is day 59 and March 1  is
1034616d0f9Sopenharmony_ci                            day  60.   It is impossible to explicitly refer to
1044616d0f9Sopenharmony_ci                            the occasional February 29.
1054616d0f9Sopenharmony_ci
1064616d0f9Sopenharmony_ci                     n      The zero-based Julian day  (0 <= n <= 365).   Leap
1074616d0f9Sopenharmony_ci                            days  are  counted, and it is possible to refer to
1084616d0f9Sopenharmony_ci                            February 29.
1094616d0f9Sopenharmony_ci
1104616d0f9Sopenharmony_ci                     Mm.n.d The d'th day (0 <= d <= 6) of week n of month m of
1114616d0f9Sopenharmony_ci                            the year (1 <= n <= 5, 1 <= m <= 12, where week  5
1124616d0f9Sopenharmony_ci                            means  "the last d day in month m" which may occur
1134616d0f9Sopenharmony_ci                            in either the fourth or the fifth week).   Week  1
1144616d0f9Sopenharmony_ci                            is  the  first  week in which the d'th day occurs.
1154616d0f9Sopenharmony_ci                            Day zero is Sunday.
1164616d0f9Sopenharmony_ci
1174616d0f9Sopenharmony_ci                     The time has  the  same  format  as  offset  except  that
1184616d0f9Sopenharmony_ci                     POSIX.1-2017  does not allow a leading sign ("-" or "+").
1194616d0f9Sopenharmony_ci                     As an extension to POSIX.1-2017, the hours part  of  time
1204616d0f9Sopenharmony_ci                     can  range from -167 through 167; this allows for unusual
1214616d0f9Sopenharmony_ci                     rules such as "the Saturday before the  first  Sunday  of
1224616d0f9Sopenharmony_ci                     March".  The default, if time is not given, is 02:00:00.
1234616d0f9Sopenharmony_ci
1244616d0f9Sopenharmony_ci       Here are some examples of TZ values that directly specify the timezone;
1254616d0f9Sopenharmony_ci       they use some of the extensions to POSIX.1-2017.
1264616d0f9Sopenharmony_ci
1274616d0f9Sopenharmony_ci       EST5   stands  for  US  Eastern Standard Time (EST), 5 hours behind UT,
1284616d0f9Sopenharmony_ci              without daylight saving.
1294616d0f9Sopenharmony_ci
1304616d0f9Sopenharmony_ci       <+12>-12<+13>,M11.1.0,M1.2.1/147
1314616d0f9Sopenharmony_ci              stands for Fiji time, 12 hours ahead of UT, springing forward on
1324616d0f9Sopenharmony_ci              November's first Sunday at 02:00, and falling back on  January's
1334616d0f9Sopenharmony_ci              second  Monday  at 147:00 (i.e., 03:00 on the first Sunday on or
1344616d0f9Sopenharmony_ci              after January 14).  The abbreviations for standard and  daylight
1354616d0f9Sopenharmony_ci              saving time are "+12" and "+13".
1364616d0f9Sopenharmony_ci
1374616d0f9Sopenharmony_ci       IST-2IDT,M3.4.4/26,M10.5.0
1384616d0f9Sopenharmony_ci              stands  for  Israel Standard Time (IST) and Israel Daylight Time
1394616d0f9Sopenharmony_ci              (IDT), 2 hours ahead of UT, springing forward on March's  fourth
1404616d0f9Sopenharmony_ci              Thursday  at  26:00 (i.e., 02:00 on the first Friday on or after
1414616d0f9Sopenharmony_ci              March 23), and falling back on October's last Sunday at 02:00.
1424616d0f9Sopenharmony_ci
1434616d0f9Sopenharmony_ci       <-04>4<-03>,J1/0,J365/25
1444616d0f9Sopenharmony_ci              stands for permanent daylight saving time,  3  hours  behind  UT
1454616d0f9Sopenharmony_ci              with  abbreviation "-03".  There is a dummy fall-back transition
1464616d0f9Sopenharmony_ci              on December 31  at  25:00  daylight  saving  time  (i.e.,  24:00
1474616d0f9Sopenharmony_ci              standard  time, equivalent to January 1 at 00:00 standard time),
1484616d0f9Sopenharmony_ci              and a simultaneous spring-forward transition  on  January  1  at
1494616d0f9Sopenharmony_ci              00:00  standard  time,  so daylight saving time is in effect all
1504616d0f9Sopenharmony_ci              year and the initial <-04> is a placeholder.
1514616d0f9Sopenharmony_ci
1524616d0f9Sopenharmony_ci       <-03>3<-02>,M3.5.0/-2,M10.5.0/-1
1534616d0f9Sopenharmony_ci              stands for time in western Greenland, 3 hours behind  UT,  where
1544616d0f9Sopenharmony_ci              clocks  follow the EU rules of springing forward on March's last
1554616d0f9Sopenharmony_ci              Sunday at 01:00 UT (-02:00 local time, i.e., 22:00 the  previous
1564616d0f9Sopenharmony_ci              day)  and  falling  back  on  October's  last Sunday at 01:00 UT
1574616d0f9Sopenharmony_ci              (-01:00  local  time,  i.e.,  23:00  the  previous  day).    The
1584616d0f9Sopenharmony_ci              abbreviations  for  standard  and daylight saving time are "-03"
1594616d0f9Sopenharmony_ci              and "-02".
1604616d0f9Sopenharmony_ci
1614616d0f9Sopenharmony_ci       If TZ specifies daylight saving time but does not specify a  rule,  and
1624616d0f9Sopenharmony_ci       the  optional tzfile(5)-format file posixrules is present in the system
1634616d0f9Sopenharmony_ci       time conversion information directory,  the  rules  in  posixrules  are
1644616d0f9Sopenharmony_ci       used,  with  the  posixrules  standard and daylight saving time offsets
1654616d0f9Sopenharmony_ci       from UT replaced by  those  specified  by  the  offset  values  in  TZ.
1664616d0f9Sopenharmony_ci       However,  the  posixrules file is obsolete: if it is present it is only
1674616d0f9Sopenharmony_ci       for backward compatibility, and it does not work reliably.   Therefore,
1684616d0f9Sopenharmony_ci       if a TZ string directly specifies a timezone with daylight saving time,
1694616d0f9Sopenharmony_ci       it should specify the daylight saving rules explicitly.
1704616d0f9Sopenharmony_ci
1714616d0f9Sopenharmony_ci       For  compatibility  with  System  V Release 3.1, a semicolon (;) may be
1724616d0f9Sopenharmony_ci       used to separate the rule from the rest of the specification;  this  is
1734616d0f9Sopenharmony_ci       an extension to POSIX.
1744616d0f9Sopenharmony_ci
1754616d0f9Sopenharmony_ci       The  tzfree function frees a timezone object tz, which should have been
1764616d0f9Sopenharmony_ci       successfully  allocated  by  tzalloc.   This  invalidates  any  tm_zone
1774616d0f9Sopenharmony_ci       pointers that tz was used to set.
1784616d0f9Sopenharmony_ci
1794616d0f9Sopenharmony_ci       The tzset function acts like tzalloc(getenv("TZ")), except it saves any
1804616d0f9Sopenharmony_ci       resulting  timezone  object  into  internal storage that is accessed by
1814616d0f9Sopenharmony_ci       localtime, localtime_r, and  mktime.   The  anonymous  shared  timezone
1824616d0f9Sopenharmony_ci       object  is  freed  by  the  next call to tzset.  If the implied call to
1834616d0f9Sopenharmony_ci       getenv fails, tzset acts like tzalloc(nullptr); if the implied call  to
1844616d0f9Sopenharmony_ci       tzalloc fails, tzset falls back on UT.
1854616d0f9Sopenharmony_ci
1864616d0f9Sopenharmony_ciRETURN VALUE
1874616d0f9Sopenharmony_ci       If  successful,  the  tzalloc function returns a nonnull pointer to the
1884616d0f9Sopenharmony_ci       newly allocated object.  Otherwise, it returns a null pointer and  sets
1894616d0f9Sopenharmony_ci       errno.
1904616d0f9Sopenharmony_ci
1914616d0f9Sopenharmony_ciERRORS
1924616d0f9Sopenharmony_ci       EOVERFLOW
1934616d0f9Sopenharmony_ci              TZ  directly specifies time conversion information, and contains
1944616d0f9Sopenharmony_ci              an integer out of machine range or a time zone abbreviation that
1954616d0f9Sopenharmony_ci              is too long for this platform.
1964616d0f9Sopenharmony_ci
1974616d0f9Sopenharmony_ci       The tzalloc function may also fail and set errno for any of the  errors
1984616d0f9Sopenharmony_ci       specified for the routines access(2), close(2), malloc(3), open(2), and
1994616d0f9Sopenharmony_ci       read(2).
2004616d0f9Sopenharmony_ci
2014616d0f9Sopenharmony_ciFILES
2024616d0f9Sopenharmony_ci       /etc/localtime                  local timezone file
2034616d0f9Sopenharmony_ci       /usr/share/zoneinfo             timezone directory
2044616d0f9Sopenharmony_ci       /usr/share/zoneinfo/posixrules  default DST rules (obsolete)
2054616d0f9Sopenharmony_ci       /usr/share/zoneinfo/GMT         for UTC leap seconds
2064616d0f9Sopenharmony_ci
2074616d0f9Sopenharmony_ci       If  /usr/share/zoneinfo/GMT is absent, UTC leap seconds are loaded from
2084616d0f9Sopenharmony_ci       /usr/share/zoneinfo/GMT0 if present.
2094616d0f9Sopenharmony_ci
2104616d0f9Sopenharmony_ciSEE ALSO
2114616d0f9Sopenharmony_ci       getenv(3), newctime(3), newstrftime(3), time(2), tzfile(5)
2124616d0f9Sopenharmony_ci
2134616d0f9Sopenharmony_ciTime Zone Database                                                 newtzset(3)
214