Subject: | [PATCH] Android support |
The attached patch adds Android support to the module.
Unfortunately, android was different enough from normal unixes that it required it's own submodule. To list a few of the things that are different on android:
- No /etc/localtime, /etc/LOCALTIME, /etc/sysconfig/clock and /etc/default/init
- No /usr/share/zoneinfo; instead, it's in /system/usr/share/zoneinfo
- /system/usr/share/zoneinfo/ is unlike every other system: it only has three files, namely zoneinfo.version, zoneinfo.dat, and zoneinfo.idx. zoneinfo.dat is basically a concatenated version of the contents of the usual zoneinfo/
On the flip side, what decides the current timezone is pretty simple[0]:
- The TZ environmental variable
- getprop persist.sys.timezone
- If neither of those returns something, then it's GMT
[0] https://chromium.googlesource.com/native_client/nacl-bionic/+/upstream/master/libc/tzcode/localtime.c has the exact order described; another relevant reference is ZoneInfoDB.java
Subject: | 0001-Android-support.patch |
From fc53f1c14afa7426728b119d2e38b7e483ee98eb Mon Sep 17 00:00:00 2001
From: Brian Fraser <fraserbn@gmail.com>
Date: Sun, 3 Aug 2014 03:37:24 +0200
Subject: [PATCH] Android support
---
lib/DateTime/TimeZone/Local.pm | 1 +
lib/DateTime/TimeZone/Local/Android.pm | 44 ++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 lib/DateTime/TimeZone/Local/Android.pm
diff --git a/lib/DateTime/TimeZone/Local.pm b/lib/DateTime/TimeZone/Local.pm
index 8e3da87..e61d3b5 100644
--- a/lib/DateTime/TimeZone/Local.pm
+++ b/lib/DateTime/TimeZone/Local.pm
@@ -34,6 +34,7 @@ sub TimeZone {
NetWare => 'Win32',
symbian => 'Win32',
dos => 'OS2',
+ android => 'Android',
cygwin => 'Unix',
);
diff --git a/lib/DateTime/TimeZone/Local/Android.pm b/lib/DateTime/TimeZone/Local/Android.pm
new file mode 100644
index 0000000..d5668c5
--- /dev/null
+++ b/lib/DateTime/TimeZone/Local/Android.pm
@@ -0,0 +1,44 @@
+package DateTime::TimeZone::Local::Android;
+
+use strict;
+use warnings;
+
+use parent 'DateTime::TimeZone::Local';
+
+sub Methods {
+ return qw(
+ FromEnv
+ FromGetProp
+ FromDefault
+ );
+}
+
+sub EnvVars { return 'TZ' }
+
+# https://chromium.googlesource.com/native_client/nacl-bionic/+/upstream/master/libc/tzcode/localtime.c
+sub FromGetProp {
+ my $name = `getprop persist.sys.timezone`;
+ chomp $name;
+ my $tz;
+ {
+ local $@;
+ local $SIG{__DIE__};
+ $tz = eval { DateTime::TimeZone->new( name => $name ) };
+ }
+
+ return $tz if $tz;
+}
+
+# See the link above. Android always defaults to GMT
+sub FromDefault {
+ my $tz;
+ {
+ local $@;
+ local $SIG{__DIE__};
+ $tz = eval { DateTime::TimeZone->new( name => 'GMT' ) };
+ }
+
+ return $tz if $tz;
+}
+
+1;
--
1.7.12.4 (Apple Git-37)