I'm adapting Strptime to return DateTime::Incomplete objects when it
gets an incomplete datetime. The old behaviour was to return the lowest
possible value.
eg. 'November 2003' used to return 2003-11-01T00:00:00, but will now
return 2003-11-xxTxx:xx:xx
I'm currently checking to see if a datetime is possible and only
returning incomplete if not. Is that a good idea?
If so, maybe a method inside Incomplete would be good:
if ($dti->can_be_datetime) {
$dti->become_datetime
}
or else an incomplete could automatically convert itself to a DateTime
once it had enough information?!?!?
I figure an Incomplete can become a DateTime if:
We have a Year, Month and Day, but no time (becomes 00:00:00) -or-
We have a Year, Month, Day, Hour and Minute -or-
We have a Year, Month, Day, Hour, Minute and Second -or-
We have a Year, Month, Day, Hour, Minute, Second and Nanosecond
But maybe that's just me.
My other option with Strptime are:
1. Always return an Incomplete object, but I doubt that's what people
would want/expect.
2. Always return an Incomplete unless we are given a base, in which case
the base fills in the blanks. This would mean if you have a full
datetime specifier in some format you still need to pass a DateTime into
the strptime object in order to receive a DateTime in return:
$strptime = new DateTime::Format::Strptime( base => DateTime->today,
pattern=$pattern );
$strptime->parse_datetime("Nov 3, 2003");
# Returns DateTime: 2003-11-03T00:00:00
$strptime = new DateTime::Format::Strptime( pattern=$pattern );
$strptime->parse_datetime("Nov 3, 2003");
# Returns DateTime::Incomplete: 2003-11-03Txx:xx:xx
3. Keep the current (shonky) behaviour
Cheers!
Rick