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

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