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: 84229
Status: resolved
Priority: 0/
Queue: DateTime

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

Bug Information
Severity: Normal
Broken in: 0.78
Fixed in: 1.00



Subject: truncate() has a validation problem
Problem: Any argument to ->truncate( to => ... ) that begins with "year", "month", "week", "day", "hour", "minute", or "second" passes validation, but if the argument isn't an exact match, truncate silently does nothing. For example, "hours" passes validation, but truncate fails. Reproduce by: print DateTime->now->truncate(to => "hours"); 2013-03-26T17:27:17 Expected result: The 'to' parameter ("hours") to DateTime::truncate did not pass regex check Here's a fix: *** DateTime.pm 2012-11-16 10:40:40.000000000 -0700 --- DateTime-rev.pm 2013-03-26 00:47:32.000000000 -0700 *************** *** 1911,1917 **** ); my $re = join '|', 'year', 'week', grep { $_ ne 'nanosecond' } keys %TruncateDefault; ! my $spec = { to => { regex => qr/^(?:$re)/ } }; sub truncate { my $self = shift; --- 1911,1917 ---- ); my $re = join '|', 'year', 'week', grep { $_ ne 'nanosecond' } keys %TruncateDefault; ! my $spec = { to => { regex => qr/^(?:$re)$/ } }; sub truncate { my $self = shift; ... or to change truncate to allow plurals: *** DateTime.pm 2012-11-16 10:40:40.000000000 -0700 --- DateTime-rev.pm 2013-03-26 00:47:32.000000000 -0700 *************** *** 1911,1917 **** ); my $re = join '|', 'year', 'week', grep { $_ ne 'nanosecond' } keys %TruncateDefault; ! my $spec = { to => { regex => qr/^(?:$re)/ } }; sub truncate { my $self = shift; --- 1911,1917 ---- ); my $re = join '|', 'year', 'week', grep { $_ ne 'nanosecond' } keys %TruncateDefault; ! my $spec = { to => { regex => qr/^(?:$re)s?$/ } }; sub truncate { my $self = shift;