Parse local time zone definition from /etc/localtime

This commit is contained in:
Petr Písař 2014-09-02 17:15:59 +02:00
parent ad505d61c1
commit 8a141164fd
2 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,78 @@
From ddb36a17bd9ab30c33532684af85c71cd5c04071 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 71d7d4e..3c24ad0 100644
--- a/lib/DateTime/TimeZone/Local/Unix.pm
+++ b/lib/DateTime/TimeZone/Local/Unix.pm
@@ -14,6 +14,7 @@ sub Methods {
FromEtcTIMEZONE
FromEtcSysconfigClock
FromEtcDefaultInit
+ FromEtcLocaltimeContent
);
}
@@ -233,6 +234,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
@@ -307,6 +327,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

View File

@ -1,11 +1,14 @@
Name: perl-DateTime-TimeZone
Version: 1.74
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Time zone object base class and factory
License: GPL+ or Artistic
Group: Development/Libraries
URL: http://search.cpan.org/dist/DateTime-TimeZone/
Source0: http://www.cpan.org/authors/id/D/DR/DROLSKY/DateTime-TimeZone-%{version}.tar.gz
# Parse local time zone definition from /etc/localtime as before giving up,
# bug #1135981, CPAN RT#55029
Patch0: DateTime-TimeZone-1.74-Parse-etc-localtime-by-DateTime-TimeZone-Tzfile.patch
BuildArch: noarch
BuildRequires: perl
BuildRequires: perl(base)
@ -40,6 +43,9 @@ BuildRequires: perl(warnings)
# not automatically detected
Requires: perl(File::Compare)
Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
# Require optional DateTime::TimeZone::Tzfile to work in mock after tzdata
# upgrade, bug #1135981
Requires: perl(DateTime::TimeZone::Tzfile)
%{?filter_setup:
%filter_from_requires /^perl(Win32/d
@ -73,6 +79,7 @@ offset from GMT for a given time period.
%prep
%setup -q -n DateTime-TimeZone-%{version}
%patch0 -p1
%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
@ -94,6 +101,9 @@ make test
%{_mandir}/man3/*
%changelog
* Tue Sep 02 2014 Petr Pisar <ppisar@redhat.com> - 1.74-2
- Parse local time zone definition from /etc/localtime (bug #1135981)
* Tue Sep 02 2014 Petr Pisar <ppisar@redhat.com> - 1.74-1
- 1.74 bump (updates to 2014g Olson database)