perl-DateTime-TimeZone/DateTime-TimeZone-1.83-Parse-etc-localtime-by-DateTime-TimeZone-Tzfile.patch

79 lines
2.3 KiB
Diff
Raw Normal View History

From fbf080cb5ca92f35a594967bdd3764c7dbb8c7f7 Mon Sep 17 00:00:00 2001
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
index ae26fae..c5d44fe 100644
--- a/lib/DateTime/TimeZone/Local/Unix.pm
+++ b/lib/DateTime/TimeZone/Local/Unix.pm
@@ -16,6 +16,7 @@ sub Methods {
FromEtcTIMEZONE
FromEtcSysconfigClock
FromEtcDefaultInit
+ FromEtcLocaltimeContent
);
}
@@ -237,6 +238,25 @@ sub _ReadEtcDefaultInit {
}
}
+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
@@ -309,6 +329,13 @@ a time zone name.
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
=head1 AUTHOR
--
1.9.3