Skip Menu |
 

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

Report information
The Basics
Id: 66091
Status: open
Priority: 0/
Queue: DateTime-Format-Natural

People
Owner: Nobody in particular
Requestors: PHILKIME [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.93
Fixed in: (no value)



Subject: No way to distinguish between empty month/day and "1"?
Download (untitled) / with headers
text/plain 932b
There doesn't seem to be a way to distinguish between: 2008 2008-01-01 I am trying to parse dates which may or may not have month/day (in bibliographies, very common) and then I need to set individual day/month/year fields. Currently, I can't find any DateTime::Format module which will not set day/month if they are not present, even though a bare year is, for example, a valid ISO8601 date. DateTime::Incomplete will perhaps do this but I can't use an object of this type as a base for DateTime::Format::Natural: DateTime::Format::Natural->new(datetime => DateTime::Incomplete->new); just dies with The 'datetime' parameter ("DateTime::Incomplete=HASH(0x1028bf0a0)") to DateTime::Format::Natural::new did not pass the 'valid object' callback .... This inability to distinguish between an empty month/day and 01/01 is quite a problem when splitting dates into components where the presence/absence of day/mont matters.
Subject: Re: [rt.cpan.org #66091] No way to distinguish between empty month/day and "1"?
Date: Sat, 26 Feb 2011 00:55:52 +0100
To: Philip Kime via RT <bug-DateTime-Format-Natural [...] rt.cpan.org>
From: Steven Schubiger <schubiger [...] cpan.org>
Download (untitled) / with headers
text/plain 1.5k
Philip Kime via RT <bug-DateTime-Format-Natural@rt.cpan.org> wrote: Show quoted text
> There doesn't seem to be a way to distinguish between: > > 2008 > 2008-01-01
The resulting dates are indistinguishable, agreed. Show quoted text
> I am trying to parse dates which may or may not have month/day (in bibliographies, very > common) and then I need to set individual day/month/year fields. Currently, I can't find any > DateTime::Format module which will not set day/month if they are not present, even though a > bare year is, for example, a valid ISO8601 date. DateTime::Incomplete will perhaps do this
DateTime::Format::Natural keeps an internal counter of units having been set or modified; furthermore, it also invokes DateTime's truncate method to finally reset time components. As a rough idea, I could imagine exposing the counter data via an accessor to the user in order to allow for it being checkable. For what it's worth, call `dateparse -T` with a recent version, enter the two date strings listed and you should see a summary of altered units for each string successfully parsed. Show quoted text
> but I can't use an object of this type as a base for DateTime::Format::Natural:
Show quoted text
> DateTime::Format::Natural->new(datetime => DateTime::Incomplete->new); > > just dies with > > The 'datetime' parameter ("DateTime::Incomplete=HASH(0x1028bf0a0)") to > DateTime::Format::Natural::new did not pass the 'valid object' callback ....
This happens because not a DateTime object was provided; DateTime::Incomplete's to_datetime method returns one (according to its documentation).


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.