Blame DateTime-TimeZone-2.04-Parse-etc-localtime-by-DateTime-TimeZone-Tzfile.patch

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