I'm not so sure that "2003" isn't a datetime - it's just one of a
rather large granularity. I mean, in a bibliography, you want to say
"Article X was published in 2003" but to say that the year of
publication there isn't really a datetime but "Article X was published
in 2003/05" or "Article X was published on 2003/05/01" does have a
publication datetime is rather odd - it's just that the granularity of
most publishing is at the year level. A naked year is also a valid
ISO8601 date. I think that since all DateTime::Format modules return
DateTime objects, the only real solution is to add some methods to
DateTime which tell you whether the datetime object has real or
default values for monthy/day (and probably time otherwise you can't
distinguish between a datetime with no time and one which starts at
midnight). This can't be that hard - nothing needs to change in the
internals, just set a flag if some input data is undef and remember
this so that the information can be retrieved with some new methods.

PK

On 24 February 2011 10:03, Rick Measham <r...@measham.id.au> wrote:
> Seems to me that "2003" isn't a datetime, nor is "2003-05-01", both are 
> spans. 2003 = '2003-01-01 00:00:00.0' - '2004-01-01 00:00:00.0'
>
> Maybe there's something that can be done with DT:Incomplete given that change 
> in perspective?
>
> Maybe DT:F:Strptime could return a DT:Incomplete as an 'error' option.
>
> No solutions, just thoughts.
>
> Cheers!
> Rick Measham
>
>
> On 24/02/2011, at 17:59, Philip Kime <philk...@kime.org.uk> wrote:
>
>> Yes, that would be fine and I could use DateTime::Incomplete to get
>> what I want but unfortunately what I need is the parsing so I don't
>> have to parse it all myself (which is what I'm currently doing). The
>> strings aren't that simple I'm afraid, that was just a minimal
>> example. In fact, the strings are so irregular in one app data source
>> driver that I really need to use DataTime::Format::Natural ...
>>
>> PK
>>
>> On 24 February 2011 01:34, Karen Etheridge <p...@froods.org> wrote:
>>> On Wed, Feb 23, 2011 at 09:23:08PM +0100, Philip Kime wrote:
>>>> All I really want is to be able to say:
>>>>
>>>> $dt = DateTime::Format::Somemodule->new('2008');
>>>>
>>>> and have $dt->month and $dt->day return undef instead of "1" otherwise I 
>>>> can't distinguish from:
>>>>
>>>> $dt = DateTime::Format::Somemodule->new('2008-01-01');
>>>>
>>>> Even DateTime::Format::ISO8601 doesn't do this even though "2008" is a 
>>>> valid ISO8601 date.
>>>
>>> If your strings really are this simple, could you not simply do $dt =
>>> DateTime->new(year => 2008);  ?  The DateTime::Format::* modules are simply
>>> string parsers which call DateTime->new with various arguments -- there is
>>> no reason why you can't call the constructor yourself.
>>>
>>>
>>>
>>> --
>>>                     "The 3 great virtues of a programmer:
>>>                Laziness, Impatience, and Hubris." - Larry Wall
>>>            .             .            .            .             .
>>> Karen Etheridge, ka...@etheridge.ca       GCS C+++$ USL+++$ P+++$ w--- M++
>>> http://etheridge.ca/                      PS++ PE-- b++ DI++++ e++ h(-)
>>>
>>
>>
>>
>> --
>> Dr Philip Kime
>> --
>> Message  protected for iSite by MailGuard: e-mail anti-virus, anti-spam and 
>> content filtering.http://www.mailguard.com.au
>> Click here to report this message as spam:
>> https://login.mailguard.com.au/report/1BMjZLkebE/36DtTOMZrBA6cRxeViXzr4/0
>>
> --
> Message  protected for iSite by MailGuard: e-mail anti-virus, anti-spam and 
> content filtering.http://www.mailguard.com.au
>
>



-- 
Dr Philip Kime

Reply via email to