Please add "0+" operator for overload. It could be possible to write:
my $dt = DateTime->now;
print scalar localtime int $dt;
Subject: | DateTime-0.4501.diff |
diff -Nru DateTime-0.4501.orig/lib/DateTime.pm DateTime-0.4501/lib/DateTime.pm
--- DateTime-0.4501.orig/lib/DateTime.pm 2008-11-25 16:10:20.000000000 +0100
+++ DateTime-0.4501/lib/DateTime.pm 2008-12-06 16:22:08.000000000 +0100
@@ -58,6 +58,7 @@
'<=>' => '_compare_overload',
'cmp' => '_compare_overload',
'""' => '_stringify',
+ '0+' => '_numerify',
'-' => '_subtract_overload',
'+' => '_add_overload',
'eq' => '_string_equals_overload',
@@ -776,6 +777,13 @@
return $self->{formatter}->format_datetime($self);
}
+sub _numerify
+{
+ my $self = shift;
+
+ return $self->epoch;
+}
+
sub hms
{
my ( $self, $sep ) = @_;
diff -Nru DateTime-0.4501.orig/t/29overload.t DateTime-0.4501/t/29overload.t
--- DateTime-0.4501.orig/t/29overload.t 2007-07-01 06:16:11.000000000 +0200
+++ DateTime-0.4501/t/29overload.t 2008-12-06 17:02:49.000000000 +0100
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 12;
+use Test::More tests => 14;
use DateTime;
@@ -13,6 +13,13 @@
}
{
+ my $dt = DateTime->new( year => 2000, month => 1, day => 1 );
+
+ is( "$dt", '2000-01-01T00:00:00', 'stringification overloading' );
+ is( int $dt, 946684800, 'numerification overloading' );
+}
+
+{
my $dt = DateTime->new( year => 2050, month => 1, day => 15,
hour => 20, minute => 10, second => 10 );