Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 41486
Status: rejected
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: piotr.roszatycki [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.4501
Fixed in: (no value)



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 );
Subject: Re: [rt.cpan.org #41486]
Date: Sat, 6 Dec 2008 10:27:47 -0600 (CST)
To: Piotr Roszatycki via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sat, 6 Dec 2008, Piotr Roszatycki via RT wrote: Show quoted text
> Sat Dec 06 11:22:14 2008: Request 41486 was acted upon. > Transaction: Ticket created by DEXTER > Queue: DateTime > Subject: (No subject given) > Broken in: 0.4501 > Severity: Wishlist > Owner: Nobody > Requestors: piotr.roszatycki@gmail.com > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=41486 > > > > Please add "0+" operator for overload. It could be possible to write: > > my $dt = DateTime->now; > print scalar localtime int $dt;
I really do not want to encourage more use of the epoch. Maybe in the future when Perl has native support for 64-bit epochs I will reconsider, but for now I think this would be a bad idea. Even worse, it would encourage people to expect numeric math to work ($dt + 100). /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/