in reply to Ignoring timezones when comparing dates with Time::Piece

The Time::Piece::Plus docs mention timezones all over the place, and if you look at the source you can see

my $self = $args->{as_localtime} ? $class->localtime() : $class->g +mtime(); my $parsed = $self->strptime($args->{str}, '%Y-%m-%d');

So there you go  gmtime()->strptime(...)

Now the question is, does this work or do something real?

I don't know because I DateTime

Replies are listed 'Best First'.
Re^2: Ignoring timezones when comparing dates with Time::Piece::Plus
by Anonymous Monk on Apr 21, 2015 at 01:47 UTC
    Awesome, thanks! Calling strptime on localtime() was the key:
    #!/usr/bin/env perl use strict; use warnings; use Time::Piece::Plus; my $today = localtime()->today; my $date = localtime()->strptime("2015-04-20", '%Y-%m-%d'); print "Date: $date tzoffset=", $date->tzoffset, "\n"; print "Today: $today tzoffset=", $today->tzoffset, "\n"; print "Diff: ", ($date - $today), "\n";
    Output:
    Date: Mon Apr 20 00:00:00 2015 tzoffset=-25200 Today: Mon Apr 20 00:00:00 2015 tzoffset=-25200 Diff: 0
    Not sure what you mean by timezones mentioned all over the place.
    $ cpanm Time::Piece Time::Piece is up to date. (1.29) $ cpanm Time::Piece::Plus Time::Piece::Plus is up to date. (0.05) $ perldoc -t Time::Piece | grep -i zone $t->tzoffset # timezone offset in a Time::Seconds o +bject $ perldoc -t Time::Piece::Plus | grep -i zone $