Re: Strptime issues
Rick Measham wrote: if ($dti-can_be_datetime) { $dti-become_datetime } implemented as: if ($dti-can_be_datetime) { $dti = $dti-become_datetime } because changing the class of '$dti' is a bit hard. How about to extend the 'to_datetime' method, instead of creating a new one: if ($dti-can_be_datetime) { $dti = $dti-to_datetime } - Flavio S. Glock
Re: Re: Strptime issues
Flavio S. Glock [EMAIL PROTECTED] wrote: How about to extend the 'to_datetime' method, instead of creating a new one: if ($dti-can_be_datetime) { $dti = $dti-to_datetime } Sounds good .. and it's as simple as using DateTime-today as the base, which may well be a good default behaviour for -to_datetime when no base is in the object or none is passed in the call. Cheers! Rick
Re: Strptime issues
[EMAIL PROTECTED] wrote: Sounds good .. and it's as simple as using DateTime-today as the base, which may well be a good default behaviour for -to_datetime when no base is in the object or none is passed in the call. So this is what we've got so far: 0.0102 2003-11-06 - to_datetime() uses today as a base date, if none was given. The following methods are affected by this change: epoch, hires_epoch, is_dst, utc_rd_values, utc_rd_as_seconds, sprintf(%s) - can_be_datetime() - has_date(), has_time() - defined_fields() method, contributed by Rick Measham - to_datetime() sets fields in a known order, instead of hash-order. Based on a patch by Rick Measham - Included has() method, contributed by Rick Measham 0.0101 2003-11-03 - runs in Perl 5.00503. Dave Rolsky Flavio S. Glock, creating a cvs conflict :) - there is no set_locale() in DateTime. Modified from a patch by Rick Measham - fixed an infinite loop in _format_nanoseconds. Patch by Rick Measham This is a sample of the new API: $dti = $dti-to_datetime; if ( $dti-can_be_datetime ) { $dti = $dti-to_datetime } else { print only @{[ $dti-defined_fields ]} are set } if ( $dti-can_be_datetime $dti-has_date ) ... if ( $dti-has_date $dti-has_time ) ... if ( $dti-has_year ) ... if ( $dti-has( qw( year month day hour ) ) ) ... - Flavio S. Glock
Re: Re: Re: Strptime issues
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: sub has_time { $_[0]-has{'hour', 'minute'} } Maybe should be: sub has_time { return 1 if ($_[0]-has('hour', 'minute') and not $_[0]-has('nanosecond')); return 1 if ($_[0]-has('hour', 'minute', 'second')) return 0 } Which only returns true if we have HH:MM or HH:MM:SS or HH:MM:SS.N+. The older version allowed us to get true for HH:MM:xx.N+ which is not really a time. Same caveat: Above code passes all tests on the perl installed in my head. Havn't tried any of it with the much fussier software version. perl -v This is perl, v5.8.0 built for ricks-brain-1.0
Re: Strptime issues
[EMAIL PROTECTED] wrote: Flavio S. Glock [EMAIL PROTECTED] wrote: * keys or defined_fields returns the list of names of defined fields sub has { # called with parameters you get true or false # called with no params and you get a list of fields I implemented this in CVS with tests, but I believe it should be 2 separate methods instead. What do you think? * can_be_datetime / become_datetime sub can_be_datetime { # -MM-DD # -MM-DD HH:MM # -MM-DD HH:MM:SS # -MM-DD HH:MM:SS.N I think any dti that has_year can become a datetime. For example, DT::I-new( year=2003 )-become_datetime-datetime 2003-01-01T00:00:00 Or perhaps, allow any dti without 'holes': -MM -MM-DD -MM-DD HH -MM-DD HH:MM -MM-DD HH:MM:SS -MM-DD HH:MM:SS.N this excludes, for example: --DD - Flavio S. Glock
Re: Re: Strptime issues
David Hood [EMAIL PROTECTED] wrote: Perhaps you should return only the information that is given, in an iso 8601 compliant format, so for November 2003 you could simply return 2003-11. The Nah, that's not going to happen. The entire point of the module is to get a DateTime object. So it's either going to be a full DateTime or a DateTime::Incomplete. Also: What's the ISO format for 11pm November?
Re: Strptime issues
Rick Measham wrote: 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 think automatic conversion is not a good thing. I'm thinking about the other alternatives... The patches were applied - thanks. - Flavio S. Glock
Re: Strptime issues
Rick Measham wrote: If so, maybe a method inside Incomplete would be good: if ($dti-can_be_datetime) { $dti-become_datetime } I've put this in the TODO. So this is the current list of proposed DT::Incomplete methods that are waiting for votes: * epoch $epoch = $dti-epoch if $dti-can_be_datetime; * has_date / has_time * keys or defined_fields returns the list of names of defined fields * join( $dti ) join the defined keys of two DT::Incomplete objects * is_incomplete / is_complete * can_be_datetime / become_datetime - Flavio S. Glock