[sf-perl] Timezone question

Earl Ruby earl at ruby.org
Mon Aug 20 17:13:53 PDT 2012


Does anyone know of a CPAN function that, when passed the name of a
timezone from zoneinfo (e.g. "America/Los_Angeles") and whether or not
daylight savings time is in effect will return the UTC offset in
seconds?

I've looked through CPAN and several modules look like they do this
but don't. Either they don't work with the zones from zoneinfo or they
won't give the offsets for standard and daylight time (only "current"
time).

I used to run /usr/sbin/zdump and then parse the output, but the
maintainers of zdump removed the GMT offset value that used to be
returned. So now instead of getting this:

America/Los_Angeles  Sun Mar 14 10:00:00 2021 UTC = Sun Mar 14
03:00:00 2021 PDT isdst=1 gmtoff=-25200

I now get this:

America/Los_Angeles  Sun Mar 14 10:00:00 2021 UTC = Sun Mar 14
03:00:00 2021 PDT isdst=1

I want something that does something like this:

my $isdst = 1;
my $offset = get_utc_offset('America/Los_Angeles', $isdst);
print "$offset\n";    # prints -25200

$isdst = 0;
$offset = get_utc_offset('America/Los_Angeles', $isdst);
print "$offset\n";    # prints -28800

-- 
Earl Ruby
http://earlruby.org/
@earlruby


More information about the SanFrancisco-pm mailing list