Change 29417 by [EMAIL PROTECTED] on 2006/11/29 12:08:35
Patch by Derek Price to Time::Piece for CPAN bug #21255:
NOTDATE - DATE should stringify DATE and let Perl handle things
Affected files ...
... //depot/perl/ext/Time/Piece/Piece.pm#13 edit
... //depot/perl/ext/Time/Piece/t/06subclass.t#2 edit
Differences ...
==== //depot/perl/ext/Time/Piece/Piece.pm#13 (text) ====
Index: perl/ext/Time/Piece/Piece.pm
--- perl/ext/Time/Piece/Piece.pm#12~29406~ 2006-11-28 06:58:14.000000000
-0800
+++ perl/ext/Time/Piece/Piece.pm 2006-11-29 04:08:35.000000000 -0800
@@ -22,7 +22,7 @@
':override' => 'internal',
);
-our $VERSION = '1.11_01';
+our $VERSION = '1.11_02';
bootstrap Time::Piece $VERSION;
@@ -540,7 +540,17 @@
if (UNIVERSAL::isa($rhs, 'Time::Seconds')) {
$rhs = $rhs->seconds;
}
- die "Can't subtract a date from something!" if shift;
+
+ if (shift)
+ {
+ # SWAPED is set (so someone tried an expression like NOTDATE - DATE).
+ # Imitate Perl's standard behavior and return the result as if the
+ # string $time resolves to was subtracted from NOTDATE. This way,
+ # classes which override this one and which have a stringify function
+ # that resolves to something that looks more like a number don't need
+ # to override this function.
+ return $rhs - "$time";
+ }
if (UNIVERSAL::isa($rhs, 'Time::Piece')) {
return Time::Seconds->new($time->epoch - $rhs->epoch);
==== //depot/perl/ext/Time/Piece/t/06subclass.t#2 (text) ====
Index: perl/ext/Time/Piece/t/06subclass.t
--- perl/ext/Time/Piece/t/06subclass.t#1~29383~ 2006-11-26 06:14:54.000000000
-0800
+++ perl/ext/Time/Piece/t/06subclass.t 2006-11-29 04:08:35.000000000 -0800
@@ -45,3 +45,22 @@
use base qw(Time::Piece);
# this package is identical, but will be ->isa('Time::Piece::Twin');
}
+
+{
+ my $class = "Time::Piece::NumString";
+ my $piece = $class->strptime ("2006", "%Y");
+ is (2007 - $piece, 1,
+ "subtract attempts stringify for unrecognized objects.");
+}
+
+## Below is a package which only changes the stringify function.
+{
+ package Time::Piece::NumString;
+ use base qw(Time::Piece);
+ use overload '""' => \&_stringify;
+ sub _stringify
+ {
+ my $self = shift;
+ return $self->strftime ("%Y");
+ }
+}
End of Patch.