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: 84777
Status: rejected
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

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



Subject: partial DateTime::Duration ordering without a base datetime
It would be nice to have a DateTime::Duration method that could "compare" without a base DateTime along the lines of the comparison specified for xs:duration... http://www.w3.org/TR/xmlschema-2/#duration This is a partial ordering, so that: 364 days < 1 year 365 days ?? 1 year 366 days ?? 1 year 367 days > 1 year I need an implementation of this, so am planning on writing it some time next week. Should I write it as a separate module, or do you want me to write it as a contribution to DateTime::Duration itself?
Subject: Re: [rt.cpan.org #84777] partial DateTime::Duration ordering without a base datetime
Date: Sun, 21 Apr 2013 10:36:21 -0500 (CDT)
To: Toby Inkster via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sun, 21 Apr 2013, Toby Inkster via RT wrote: Show quoted text
> Sun Apr 21 07:41:39 2013: Request 84777 was acted upon. > Transaction: Ticket created by TOBYINK > Queue: DateTime > Subject: partial DateTime::Duration ordering without a base datetime > Broken in: (no value) > Severity: Wishlist > Owner: Nobody > Requestors: mail@tobyinkster.co.uk > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=84777 > > > > It would be nice to have a DateTime::Duration method that could "compare" without a base DateTime along the lines of the comparison specified for xs:duration... > > http://www.w3.org/TR/xmlschema-2/#duration > > This is a partial ordering, so that: > > 364 days < 1 year > 365 days ?? 1 year > 366 days ?? 1 year > 367 days > 1 year > > I need an implementation of this, so am planning on writing it some time next week. Should I write it as a separate module, or do you want me to write it as a contribution to DateTime::Duration itself?
I don't think this really belongs in the core class. It seems like it's specific to XML Schema, so it's best as a separate module. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
OK. Well, FYI, turns out to be surprisingly easy: sub duration_compare { { "-1-1-1-1" => -1, "0000" => 0, "1111" => 1 }->{ join q[], map "DateTime::Duration"->compare(@_[0,1], $_), map +( /^(\d{4})-(\d{2})-(\d{2})$/ && "DateTime"->new( year => $1, month => $2, day => $3, hour => 0, minute => 0, second => 0, nanosecond => 0, time_zone => "UTC", ) ), qw( 1696-09-01 1697-02-01 1903-03-01 1903-07-01 ) } } This will tell you that 2 years is longer than 729 days; but 2 years versus 730 or 731 days is indeterminable; while 2 years is shorter than 732 days. Those four dates are seemingly magic.
Subject: Re: [rt.cpan.org #84777] partial DateTime::Duration ordering without a base datetime
Date: Mon, 22 Apr 2013 14:07:27 -0500 (CDT)
To: Toby Inkster via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sun, 21 Apr 2013, Toby Inkster via RT wrote: Show quoted text
> Queue: DateTime > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=84777 > > > OK. Well, FYI, turns out to be surprisingly easy: > > sub duration_compare > { > { "-1-1-1-1" => -1, "0000" => 0, "1111" => 1 }->{ > join q[], > map "DateTime::Duration"->compare(@_[0,1], $_), > map +( > /^(\d{4})-(\d{2})-(\d{2})$/ && "DateTime"->new( > year => $1, > month => $2, > day => $3, > hour => 0, > minute => 0, > second => 0, > nanosecond => 0, > time_zone => "UTC", > ) > ), > qw( 1696-09-01 1697-02-01 1903-03-01 1903-07-01 ) > } > } > > This will tell you that 2 years is longer than 729 days; but 2 years versus 730 or 731 days is indeterminable; while 2 years is shorter than 732 days.
It's not that it's easy or difficult, it's that Perl doesn't really support the nothing of "indeterminate" when sorting things, so it doesn't make much sense to me to have this be core behavior. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/