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