Skip Menu |

This queue is for tickets about the Time-Piece CPAN distribution.

Report information
The Basics
Id: 24428
Status: resolved
Priority: 0/
Queue: Time-Piece

People
Owner: Nobody in particular
Requestors: TJENNESS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in:
  • 1.08
  • 1.10
  • 1.11
Fixed in: (no value)



Subject: strptime does not correctly inherit the local/ut time of object
The strptime() method attempts to return a Time::Piece object in the same class as the object on which the strptime() method was invoked. In v1.07 and earlier the following code returns a localtime object: $dummy = Time::Piece::localtime( 0 ); $local = $dummy->strptime( $date, $format ); in v1.08 and above it always returns a UT object. The problem is that between v1.07 and v1.08 the XS strptime function added additional dummy values to the return array but the strptime perl method was not modified to take that into account. All the values returned from strptime are passed to _mktime() and the additional islocal variable ends up in index 11 of the array and so is ignored. There are many fixes (the easiest involving removing the elements from XS strptime, making _mktime count the supplied values) for this bug.
From: PURDY [...] cpan.org
Please fix this! I ran into this in some comparisons where I'm trying to make sure a user isn't entering an old date/time. Here's a small test case: use Test::More qw( no_plan ); use Time::Piece; my $date_to_test = `date --iso-8601`; $date_to_test =~ m%^(\d+)-(\d+)-(\d+)%; ok( $1, "got a year: $1" ); ok( $2, "got a month: $2" ); ok( $3, "got a day: $3" ); my $datetime = "$1-$2-$3 "; $date_to_test = `date`; $date_to_test =~ m%(\d+):(\d+):\d+%; ok( $1, "got an hour (24h format): $1" ); ok( $2, "got a minute: $2" ); my $hour; if ( $1 < 23 ) { $hour = $1+1; } else { die "arg, run the test after midnight!"; } $datetime .= "$hour:$2"; print "DATETIME = $datetime\n"; my $now = localtime; my $later = Time::Piece->strptime( $datetime, '%Y-%m-%d %H:%M' ); ok( $later > $now, 'later is greater than now' ); And here's an even smaller one, though it's time-sensitive (you'll have to change the date/time to something an hour or two from the current time): use Test::More qw( no_plan ); use Time::Piece::MySQL; my $today = localtime; my $user_dt = Time::Piece->strptime( '2007-03-14 18:00', '%Y-%m-%d %H:%M' ); ok( $user_dt > $today, 'user date in the future is > right now' ); print "All done\n";
On Wed Jan 17 20:51:47 2007, TJENNESS wrote: Show quoted text
> in v1.08 and above it always returns a UT object. > The problem is that between v1.07 and v1.08 > the XS strptime function added additional > dummy values to the return array but the strptime > perl method was not modified to take that into account. > All the values returned from strptime are passed to > _mktime() and the additional islocal variable ends up in > index 11 of the array and so is ignored.
Please apply the attached patch to fix this bug. Thanks, Eric
Show quoted text
> Please apply the attached patch to fix this bug.
--- original/Time/Piece.pm 2008-03-02 12:15:01.000000000 -0800 +++ Time/Piece.pm 2008-12-19 16:47:04.000000000 -0800 @@ -469,6 +469,7 @@ my $format = @_ ? shift(@_) : "%a, %d %b %Y %H:%M:%S %Z"; my @vals = _strptime($string, $format); # warn(sprintf("got vals: %d-%d-%d %d:%d:%d\n", reverse(@vals))); + splice(@vals, c_islocal); # don't overflow _mktime() return scalar $time->_mktime(\@vals, (ref($time) ? $time->[c_islocal] : 0)); }
Fixed in svn. New release imminent.