2015-01-29 07:59:39 +00:00
|
|
|
From fbf080cb5ca92f35a594967bdd3764c7dbb8c7f7 Mon Sep 17 00:00:00 2001
|
2014-09-02 15:15:59 +00:00
|
|
|
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
|
|
|
|
Date: Mon, 1 Sep 2014 17:37:12 +0200
|
|
|
|
Subject: [PATCH] Parse /etc/localtime by DateTime::TimeZone::Tzfile
|
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
If there is valid /etc/localtime, then the system has configured local
|
|
|
|
time. If the file is not a symlink to /usr/share/zoneinfo or a copy
|
|
|
|
from there, then it's still a valid configuration. The only issue is
|
|
|
|
one cannot know the time zone name (Unfortunately, the time zone
|
|
|
|
abbreviations are ambiguous.)
|
|
|
|
|
|
|
|
This patch implements this scenario and caused returning
|
|
|
|
a DateTime::TimeZone::Tzfile object instead of dying with
|
|
|
|
"Cannot determine local time zone" message.
|
|
|
|
|
|
|
|
Signed-off-by: Petr Písař <ppisar@redhat.com>
|
|
|
|
---
|
|
|
|
lib/DateTime/TimeZone/Local/Unix.pm | 27 +++++++++++++++++++++++++++
|
|
|
|
1 file changed, 27 insertions(+)
|
|
|
|
|
|
|
|
diff --git a/lib/DateTime/TimeZone/Local/Unix.pm b/lib/DateTime/TimeZone/Local/Unix.pm
|
2015-01-29 07:59:39 +00:00
|
|
|
index ae26fae..c5d44fe 100644
|
2014-09-02 15:15:59 +00:00
|
|
|
--- a/lib/DateTime/TimeZone/Local/Unix.pm
|
|
|
|
+++ b/lib/DateTime/TimeZone/Local/Unix.pm
|
2016-09-27 11:51:55 +00:00
|
|
|
@@ -19,6 +19,7 @@ sub Methods {
|
2014-09-02 15:15:59 +00:00
|
|
|
FromEtcTIMEZONE
|
|
|
|
FromEtcSysconfigClock
|
|
|
|
FromEtcDefaultInit
|
|
|
|
+ FromEtcLocaltimeContent
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-14 08:26:48 +00:00
|
|
|
@@ -267,6 +268,25 @@ sub _ReadEtcDefaultInit {
|
2016-07-18 08:02:38 +00:00
|
|
|
close $fh or die $!;
|
2014-09-02 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+sub FromEtcLocaltimeContent {
|
|
|
|
+ my $class = shift;
|
|
|
|
+
|
|
|
|
+ my $lt_file = $class->_EtcFile('localtime');
|
|
|
|
+ return unless -r $lt_file && -s $lt_file && ! -l $lt_file;
|
|
|
|
+
|
|
|
|
+ my $tz;
|
|
|
|
+ {
|
|
|
|
+ local $@;
|
|
|
|
+ local $SIG{__DIE__};
|
|
|
|
+ $tz = eval {
|
|
|
|
+ require DateTime::TimeZone::Tzfile;
|
|
|
|
+ DateTime::TimeZone::Tzfile->new($lt_file);
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $tz if $tz;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
1;
|
|
|
|
|
|
|
|
# ABSTRACT: Determine the local system's time zone on Unix
|
2018-05-14 08:26:48 +00:00
|
|
|
@@ -341,6 +361,13 @@ a time zone name.
|
2014-09-02 15:15:59 +00:00
|
|
|
If this file exists, it is opened and we look for a line starting like
|
|
|
|
"TZ=...". If this is found, it should indicate a time zone name.
|
|
|
|
|
|
|
|
+=item * F</etc/localtime> content
|
|
|
|
+
|
|
|
|
+If this file is not a symlink, it's parsed by
|
|
|
|
+a L<DateTime::TimeZone::Tzfile> to retrieve the time zone offset
|
|
|
|
+definition. No time zone name will be defined. This is usefull if the
|
|
|
|
+file does not present in the system time zone database.
|
|
|
|
+
|
|
|
|
=back
|
|
|
|
|
2016-03-24 14:05:13 +00:00
|
|
|
=head1 SUPPORT
|
2014-09-02 15:15:59 +00:00
|
|
|
--
|
|
|
|
1.9.3
|
|
|
|
|