1DateTime::TimeZone::LocUasle:r:UCnoinxt(r3i)buted Perl DDoactuemTeinmtea:t:iToinmeZone::Local::Unix(3)
2
3
4
6 DateTime::TimeZone::Local::Unix - Determine the local system's time
7 zone on Unix
8
10 version 2.60
11
13 my $tz = DateTime::TimeZone->new( name => 'local' );
14
15 my $tz = DateTime::TimeZone::Local->TimeZone();
16
18 This module provides methods for determining the local time zone on a
19 Unix platform.
20
22 This class tries the following methods of determining the local time
23 zone:
24
25 • $ENV{TZ}
26
27 It checks $ENV{TZ} for a valid time zone name.
28
29 • /etc/localtime
30
31 If this file is a symlink to an Olson database time zone file
32 (usually in /usr/share/zoneinfo) then it uses the target file's
33 path name to determine the time zone name. For example, if the path
34 is /usr/share/zoneinfo/America/Chicago, the time zone is
35 "America/Chicago".
36
37 Some systems just copy the relevant file to /etc/localtime instead
38 of making a symlink. In this case, we look in /usr/share/zoneinfo
39 for a file that has the same size and content as /etc/localtime to
40 determine the local time zone.
41
42 • /etc/timezone
43
44 If this file exists, it is read and its contents are used as a time
45 zone name.
46
47 • /etc/TIMEZONE
48
49 If this file exists, it is opened and we look for a line starting
50 like "TZ = ...". If this is found, it should indicate a time zone
51 name.
52
53 • /etc/sysconfig/clock
54
55 If this file exists, it is opened and we look for a line starting
56 like "TIMEZONE = ..." or "ZONE = ...". If this is found, it should
57 indicate a time zone name.
58
59 • /etc/default/init
60
61 If this file exists, it is opened and we look for a line starting
62 like "TZ=...". If this is found, it should indicate a time zone
63 name.
64
65 • /etc/localtime content
66
67 If this file is not a symlink, it's parsed by a
68 DateTime::TimeZone::Tzfile to retrieve the time zone offset
69 definition. No time zone name will be defined. This is usefull if
70 the file does not present in the system time zone database.
71
72 Note: Some systems such as virtual machine boxes may lack any of these
73 files. You can confirm that this is case by running:
74
75 $ ls -l /etc/localtime /etc/timezone /etc/TIMEZONE \
76 /etc/sysconfig/clock /etc/default/init
77
78 If this is the case, then when checking for timezone handling you are
79 likely to get an exception:
80
81 $ perl -wle 'use DateTime; DateTime->now( time_zone => "local" )'
82 Cannot determine local time zone
83
84 In that case, you should consult your system man pages for details on
85 how to address that problem. In one such case reported to us, a FreeBSD
86 virtual machine had been built without any of these files. The user was
87 able to run the FreeBSD tzsetup utility. That installed /etc/localtime,
88 after which the above timezone diagnostic ran silently, i.e., without
89 throwing an exception.
90
92 Bugs may be submitted at
93 <https://github.com/houseabsolute/DateTime-TimeZone/issues>.
94
96 The source code repository for DateTime-TimeZone can be found at
97 <https://github.com/houseabsolute/DateTime-TimeZone>.
98
100 Dave Rolsky <autarch@urth.org>
101
103 This software is copyright (c) 2023 by Dave Rolsky.
104
105 This is free software; you can redistribute it and/or modify it under
106 the same terms as the Perl 5 programming language system itself.
107
108 The full text of the license can be found in the LICENSE file included
109 with this distribution.
110
111
112
113perl v5.36.0 2023-03-29DateTime::TimeZone::Local::Unix(3)