Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: degatcpan [...] ntlworld.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.15
Fixed in: (no value)



Subject: Removing 12 months doesn't always work
In January, removing 12 months (or exact multiple of 12) from a date will result in a date with an extra 12 months removed. *** use Time::Piece; my $date = Time::Piece->strptime("01 01 2010","%d %m %Y"); print $date->add_months(-12), "\n"; Tue Jan 1 00:00:00 2008 *** The correct date should be Tue Jan 1 00:00:00 2009
The following (and attached) patch fixes the behavior mentioned. However it may have unintended consequences. --- /usr/local/lib/perl/5.10.0/Time/Piece.pm 2010-01-10 21:57:39.000000000 +0000 +++ ./Time/Piece.pm 2010-01-10 21:58:55.000000000 +0000 @@ -602,7 +602,11 @@ if ($final_month > 11 || $final_month < 0) { # these two ops required because we have no POSIX::floor and don't # want to load POSIX.pm - $num_years = int($final_month / 12); + if ($final_month > 0) { + $num_years = int($final_month / 12); + } else { + $num_years = int($final_month / 13); + } $num_years-- if ($final_month < 0); $final_month = $final_month % 12;
Subject: patch.txt
--- /usr/local/lib/perl/5.10.0/Time/Piece.pm 2010-01-10 21:57:39.000000000 +0000 +++ ./Time/Piece.pm 2010-01-10 21:58:55.000000000 +0000 @@ -602,7 +602,11 @@ if ($final_month > 11 || $final_month < 0) { # these two ops required because we have no POSIX::floor and don't # want to load POSIX.pm - $num_years = int($final_month / 12); + if ($final_month > 0) { + $num_years = int($final_month / 12); + } else { + $num_years = int($final_month / 13); + } $num_years-- if ($final_month < 0); $final_month = $final_month % 12;
You actually need this patch: Index: Piece.pm =================================================================== --- Piece.pm (revision 83) +++ Piece.pm (working copy) @@ -601,7 +601,12 @@ if ($final_month > 11 || $final_month < 0) { # these two ops required because we have no POSIX::floor and don't # want to load POSIX.pm - $num_years = int($final_month / 12); + if ($final_month < 0 && $final_month % 12 == 0) { + $num_years = int($final_month / 12) + 1; + } + else { + $num_years = int($final_month / 12); + } $num_years-- if ($final_month < 0); $final_month = $final_month % 12;
Fixed in SVN. New release imminent.