File: Android.pm

package info (click to toggle)
libdatetime-timezone-perl 1%3A1.75-2%2B2018e
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-updates
  • size: 191,260 kB
  • sloc: perl: 2,767; sh: 42; makefile: 14
file content (44 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package DateTime::TimeZone::Local::Android;
$DateTime::TimeZone::Local::Android::VERSION = '1.75';
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 UTC
sub FromDefault {
    my $tz;
    {
        local $@;
        local $SIG{__DIE__};
        $tz = eval { DateTime::TimeZone->new( name => 'UTC' ) };
    }

    return $tz if $tz;
}

1;