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

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