Skip Menu |

This queue is for tickets about the Rose-DateTime CPAN distribution.

Report information
The Basics
Id: 84068
Status: resolved
Priority: 0/
Queue: Rose-DateTime

People
Owner: Nobody in particular
Requestors: bailey.charles [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.537
Fixed in: 0.538



Subject: parse_date('today') tries to set via read-only accessors
Rose::DateTime::Util::parse_date() handles the 'today' token by calling DateTime->now() and then attempting to set the hour, minute, and second fields to 0. However, at least in the current version of DateTime, the accessors for individual elements are read-only, so parse_date() generates warning messages and the time fields are not reset. As a result parse_date('today') == parse_date('now'). The attached patch fixes the code path for 'today' to use truncate() instead, and adds tests for 'today' and 'now'.
Subject: Rose-DateTime-Util_today.patch
--- lib/Rose/DateTime/Util.pm~ 2011-02-19 10:53:12.000000000 -0400 +++ lib/Rose/DateTime/Util.pm 2013-03-19 10:58:55.000000000 -0400 @@ -204,9 +204,7 @@ elsif($arg =~ /^today$/i) { $date = DateTime->now(time_zone => $time_zone); - $date->hour(0); - $date->minute(0); - $date->second(0); + $date->truncate(to => 'day'); } elsif($arg =~ /^(-)?infinity$/i) { --- t/basic.t~ 2011-05-04 22:15:17.000000000 -0400 +++ t/basic.t 2013-03-19 10:58:01.000000000 -0400 @@ -2,7 +2,7 @@ use strict; -use Test::More tests => 5527; +use Test::More tests => 5531; BEGIN { @@ -334,6 +334,30 @@ ok($d == $d2, 'parse_date(m/d/yyyy ham) 2'); my $now = parse_date('now'); +my $dtnow = DateTime->now->truncate(to => 'minute'); +ok($now && $now->isa('DateTime'), 'now'); + +# Time marches on; did we cross minute? +if ($now) +{ + $now->truncate(to => 'minute'); + $now = parse_date('now')->truncate(to => 'minute') + unless $now == $dtnow; +} +is($now, $dtnow, 'now is current'); + +my $today = parse_date('today'); +my $dttoday = DateTime->now->truncate(to => 'day'); +ok($today && $today->isa('DateTime'), 'today'); + +# Similarly for midnight +if ($today and $today != $dttoday) +{ + $today = parse_date('today'); +} +is($today, $dttoday, 'today is current'); + + my $inf = parse_date('infinity'); my $ninf = parse_date('-infinity');
This is fixed in Rose::DateTime 0.538, just uploaded to CPAN.