I have an application where I am usinf Time::Piece to parse times and do some calculations based on them. But today I discovered a wierdness which leads me to believe that the module does not understand Time at all!
If I take a localtime and create an object $t, then I take a string and parse it using either the
method or theTime::Piece->from_mysql_datetime()
method, then next I subtract one from the other. I always get a difference which is 5 hours too great! The following code will demonstrate the problem (Well I hope it will on your machine!) I just need a sanity check form someone before I send this to the module author.Time::Piece->strptime()
The code
#!/usr/local/bin/perl use strict; use warnings; use Time::Piece::MySQL; use Time::Seconds; use Data::Dumper; my $time = localtime; my $future_time = $time + ONE_HOUR; my $diff = $future_time - $time; print "Local time: " . $time . "\n"; print "Future time: " . $future_time . "\n"; print "Difference: " . $diff->hours . "hours \n"; print Dumper( $time, $future_time, $diff); my $test_time = Time::Piece->from_mysql_datetime( '2004-03-05 20:30:00 +' ); print Dumper $test_time; print "Test time: " . $test_time . "\n"; $diff = $test_time - $time; print $diff->minutes . " minutes\n"; $test_time = Time::Piece->strptime( '2004-03-05 20:30:00', '%Y-%m-%d % +H:%M:%S' ); print Dumper $test_time; print "Test time: " . $test_time . "\n"; $diff = $test_time - $time; print $diff->minutes . " minutes\n";
[root@posiedon3 johnday]# perl timepiece.pl Local time: Fri Mar 5 20:44:17 2004 Future time: Fri Mar 5 21:44:17 2004 Difference: 1hours $VAR1 = bless( [ 17, 44, 20, 5, 2, 104, 5, 64, 0, 1078537457, 1 ], 'Time::Piece' ); $VAR2 = bless( [ 17, 44, 21, 5, 2, 104, 5, 64, 0, 1078541057, 1 ], 'Time::Piece' ); $VAR3 = bless( do{\(my $o = 3600)}, 'Time::Seconds' ); $VAR1 = bless( [ 0, 30, 20, 5, 2, 104, 5, 64, 0, undef, 0, 0 ], 'Time::Piece' ); Test time: Fri Mar 5 20:30:00 2004 -314.283333333333 minutes $VAR1 = bless( [ 0, 30, 20, 5, 2, 104, 5, 64, 0, undef, 0, 0 ], 'Time::Piece' ); Test time: Fri Mar 5 20:30:00 2004 -314.283333333333 minutes
In reply to Time::Piece wierdness - sanity check please! by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |