[sf-perl] Timezone question
Earl Ruby
earl at ruby.org
Tue Aug 21 10:58:36 PDT 2012
I'd looked at Time::Timezone, Time::Zone, Time::ZoneInfo, and some
other packages under Time::, but not DateTime::TimeZone. Thanks, I'll
check it out.
On Mon, Aug 20, 2012 at 5:56 PM, Joseph Brenner <doom at kzsu.stanford.edu> wrote:
> Earl Ruby <earl at ruby.org> wrote:
>> 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).
>
> Have you looked at DateTime::TimeZone?
>
> http://search.cpan.org/~drolsky/DateTime-TimeZone-1.48/lib/DateTime/TimeZone.pm
>
> You can use it like this to get the offset:
>
> use DateTime;
> use DateTime::TimeZone;
>
> my $tz = DateTime::TimeZone->new( name => 'America/Chicago' );
>
> my $dt = DateTime->now();
> my $offset = $tz->offset_for_datetime($dt);
>
>
> And I would guess you could use "is_dst_for_datetime" to
> determine if you're in daylight savings time.
--
Earl Ruby
http://earlruby.org/
@earlruby
More information about the SanFrancisco-pm
mailing list