1DateTime::TimeZone::LocUasle(r3)Contributed Perl DocumenDtaatteiToinme::TimeZone::Local(3)
2
3
4
6 DateTime::TimeZone::Local - Determine the local system's time zone
7
9 version 2.52
10
12 my $tz = DateTime::TimeZone->new( name => 'local' );
13
14 my $tz = DateTime::TimeZone::Local->TimeZone();
15
17 This module provides an interface for determining the local system's
18 time zone. Most of the functionality for doing this is in OS-specific
19 subclasses.
20
22 This class provides the following methods:
23
24 DateTime::TimeZone::Local->TimeZone()
25 This attempts to load an appropriate subclass and asks it to find the
26 local time zone. This method is called by when you pass "local" as the
27 time zone name to "DateTime:TimeZone->new()".
28
29 If your OS is not explicitly handled, you can create a module with a
30 name of the form "DateTime::TimeZone::Local::$^O". If it exists, it
31 will be used instead of falling back to the Unix subclass.
32
33 If no OS-specific module exists, we fall back to using the Unix
34 subclass.
35
36 See DateTime::TimeZone::Local::Unix,
37 DateTime::TimeZone::Local::Android, DateTime::TimeZone::Local::hpux,
38 DateTime::TimeZone::Local::Win32, and DateTime::TimeZone::Local::VMS
39 for OS-specific details.
40
42 If you want to make a new OS-specific subclass, there are several
43 methods provided by this module you should know about.
44
45 $class->Methods()
46 This method should be provided by your class. It should provide a list
47 of methods that will be called to try to determine the local time zone.
48
49 Each of these methods is expected to return a new "DateTime::TimeZone"
50 object if it can successfully determine the time zone.
51
52 $class->FromEnv()
53 This method tries to find a valid time zone in an %ENV value. It calls
54 "$class->EnvVars()" to determine which keys to look at.
55
56 To use this from a subclass, simply return "FromEnv" as one of the
57 items from "$class->Methods()".
58
59 $class->EnvVars()
60 This method should be provided by your subclass. It should return a
61 list of env vars to be checked by "$class->FromEnv()".
62
63 Your class should always include the "TZ" key as one of the variables
64 to check.
65
66 $class->_IsValidName($name)
67 Given a possible time zone name, this returns a boolean indicating
68 whether or not the name looks valid. It always return false for "local"
69 in order to avoid infinite loops.
70
72 Here is a simple example subclass:
73
74 package DateTime::TimeZone::SomeOS;
75
76 use strict;
77 use warnings;
78
79 use base 'DateTime::TimeZone::Local';
80
81
82 sub Methods { qw( FromEnv FromEther ) }
83
84 sub EnvVars { qw( TZ ZONE ) }
85
86 sub FromEther
87 {
88 my $class = shift;
89
90 ...
91 }
92
94 Bugs may be submitted at
95 <https://github.com/houseabsolute/DateTime-TimeZone/issues>.
96
98 The source code repository for DateTime-TimeZone can be found at
99 <https://github.com/houseabsolute/DateTime-TimeZone>.
100
102 Dave Rolsky <autarch@urth.org>
103
105 This software is copyright (c) 2022 by Dave Rolsky.
106
107 This is free software; you can redistribute it and/or modify it under
108 the same terms as the Perl 5 programming language system itself.
109
110 The full text of the license can be found in the LICENSE file included
111 with this distribution.
112
113
114
115perl v5.34.0 2022-03-24 DateTime::TimeZone::Local(3)