Re: DT::Incomplete more methods

2003-11-04 Thread Joshua Hoblitt
On Tue, 4 Nov 2003, Flavio S. Glock wrote:

> Joshua Hoblitt wrote:
> >
> > >   $span = $dti->span;
> >
> > I really like the idea of being able to measure
> > the uncertainty in an object.  What if the year
> > and day are known but not the month?  Would a
> > span set be returned?
>
> "spanset" would be a separate method. Here is an example:

Looks good.

-J

--


New module

2003-11-04 Thread Dean Thayer
Is anyone working on a module to convert time strings in the format used by Tivoli 
Enterprise Console to DateTime objects?  I was going to do so, and I figured I would 
check.  Also, would you want that module included in the DateTime bundle, or should I 
simply put it in the Tivoli::TEC module I was planning on writing?  The Tivoli 
Enterprise Console date string format in strftime(3c) format is:

%h %e %k:%M:%S %Y




Dean Thayer
ESM Specialist
Gordon Food Service

"May grace and peace be yours from God our Father and from the Lord Jesus Christ.  He 
died for our sins, just as God our Father planned, in order to rescue us from this 
evil world in which we live.  That is why all glory belongs to God through all the 
ages of eternity.  Amen." -Galations 1:3, NLT



Re: Re: Strptime issues

2003-11-04 Thread rickmeasham
> Flavio S. Glock <[EMAIL PROTECTED]> wrote: 
> > sub has { 
>  
> I implemented this in CVS with tests, but I believe it  
> should be 2 separate methods instead. What do 
you think? 
 
I'm cool with two different methods ... it really is two 
different things. Maybe there's also a need for 
has_any('hour', 'minute') which returns true if it has 
either of hours or minutes. 
 
> > >   * can_be_datetime / become_datetime 
> > sub can_be_datetime { 
> 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 
 
Hmmm ... I think this is OK, but I'd like some way then 
to control what is required.  
 
$dti->become_datetime if 
$dti->can_be_datetime('minutes')  
 
requires: 
   -MM-DD HH:MM 
   -MM-DD HH:MM:SS 
   -MM-DD HH:MM:SS.N 
and not 
   -MM-DD HH:MM:xx.N 
 
That is, it must have years to minutes and no holes. 
 
 


Re: Strptime issues

2003-11-04 Thread Flavio S. Glock
[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: Re: Strptime issues

2003-11-04 Thread rickmeasham
> [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: Re: Strptime issues

2003-11-04 Thread rickmeasham
[webmail logged me out, so sorry if you get ++ copies] 
 
> Flavio S. Glock <[EMAIL PROTECTED]> wrote:  
> 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;  
  
Sounds good  
sub epoch {  
   my $self = shift;  
   return undef unless $self->can_be_datetime;  
   return $self->clone->become_datetime->epoch;  
}  
  
>   * has_date / has_time  
  
Sounds good, see below and:  
sub has_time { $_[0]->has{'hour', 'minute'} }  
sub has_date { $_[0]->has{'year', 'month', 'day'} }  
  
  
>   * 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  
   my $self = shift;  
   if (@_) {  
  foreach (@_) {  
 return 0 unless exists $self->{has}{$_}  
  }  
  return 1  
   }  
  return keys %{$self->{has}}  
}  
  
Which gives:  
   print "Got hour" if $dti->has('hour');  
   print "Got time" if $dti->has('hour', 'minute')  
and  
   print "Object has " . join(', ', @{$dti->has} );  
  
  
>   * join( $dti )  
> join the "defined" keys of two DT::Incomplete  
objects  
  
'join' feels like 'append'. 'union' feels better, but relates  
to sets. Maybe 'merge'? Also consider 'overlay'.  
  
dti1 2003-xx-21Txx:18:xx.12345  
dti2 2003-09-22T15:17:xx.x  
  
merge:   2003-09-21T15:18:xx.12345  
overlay: 2003-09-22T15:17:xx.12345  
  
Note that $dti1->overlay($dti2) is the same as  
$dti2->merge($dti1);  
  
  
sub merge { # not 'submerge'!!!  
   my $self = shift;  
   my $dti = shift;  
   die "Argument to merge must be a DateTime or  
DateTime::Incomplete" unless  
ref($dti)=~/^DateTime(::Incomplete)?$/;  
   # There must be a better way to do this:  
   $self->{has}{year} ||= $dti->year;  
   $self->{has}{month} ||= $dti->month;  
   $self->{has}{day} ||= $dti->day;  
   $self->{has}{hour} ||= $dti->hour;  
   $self->{has}{minute} ||= $dti->minute;  
   $self->{has}{second} ||= $dti->second;  
   $self->{has}{nanosecond} ||= $dti->nanosecond;  
  
   $self->{has}{time_zone} ||= $dti->time_zone;  
   $self->{has}{locale} ||= $dti->locale;  
   return $self  
}  
  
sub overlay { $_[0] = $_[1]->clone->merge( $_[0] )  }  
### PROBABLY A VERY UN-KOSHER WAY TO DO  
IT! ###  
  
>   * is_incomplete / is_complete  
  
sub is_complete { $_[0]->has('year', 'month', 'day',  
'hour', 'minute', 'second', 'nanosecond') }  
  
sub is_incomplete { ($_[0]->is_complete) ? 0 : 1 }  
  
  
>   * can_be_datetime / become_datetime  
  
sub can_be_datetime {  
   my $self = shift;  
   # -MM-DD HH:MM:SS  
   # -MM-DD HH:MM:SS.N  
   return 1 if $self->has('year', 'month', 'day', 'hour',  
'minute', 'second');   
  
   # -MM-DD HH:MM  
   # -MM-DD HH:MM::SS, but is already caught  
   return 1 if $self->has('year', 'month', 'day', 'hour',  
'minute') and not $self->has('nanosecond');  
  
   # -MM-DD  
   return 1 if $self->has('year', 'month', 'day')  
  and not ($self->has('hour')  
 or $self->has('minute')  
 or $self->has('second')  
 or $self->has('nanosecond')  
  );  
  return 0;  
}  
  
sub become_datetime {  
   my $self = shift;  
   return undef unless $self->can_be_datetime;   
   my $dt = DateTime->new(  
  year => $self->year,  
  month => $self->month,  
  day => $self->day,  
   );  
   $dt->set_time_zone( $self->time_zone )   
  if $self->has('time_zone');  
   $dt->set( locale => $self->locale )   
  if $self->has('locale');  
   $dt->set( hour => $self->hour, minute => $minute )  
  if $self->has('hour', 'minute');  
   $dt->set( second => $self->second )   
  if $self->has('second');  
   $dt->set( nanosecond => $self->nanosecond )   
  if $self->has('nanosecond');  
   $self = $dt;  DOES THAT DO THE TRICK, OR  
IS IT MORE COMPLEX?   
   return $self;  
}  
  
  
  
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: DT::Incomplete more methods

2003-11-04 Thread Flavio S. Glock
Joshua Hoblitt wrote:
> 
> >   $span = $dti->span;
> 
> I really like the idea of being able to measure
> the uncertainty in an object.  What if the year 
> and day are known but not the month?  Would a 
> span set be returned?

"spanset" would be a separate method. Here is an example:

With 'year' -

  $dti = DateTime::Incomplete->new( year=>2003, day=>7 );

  start:  DateTime =  2003-01-07T00:00:00 

  end:DateTime =  2003-12-08T00:00:00 

  span:  DateTime::Span =
  [ 2003-01-07T00:00:00 , 2003-12-08T00:00:00 )

  spanset:  DateTime::SpanSet =
  [ 2003-01-07T00:00:00 , 2003-01-08T00:00:00 )
  [ 2003-02-07T00:00:00 , 2003-02-08T00:00:00 )
  [ 2003-03-07T00:00:00 , 2003-03-08T00:00:00 )
  ...
  [ 2003-12-07T00:00:00 , 2003-12-08T00:00:00 )

  recurrence:  DateTime::Set =
  2003-01-07T00:00:00 ,
  2003-01-07T00:00:01 ,
  2003-01-07T00:00:02 ,
  ...
  2003-01-07T23:59:59 ,
  2003-02-07T00:00:00 ,
  ...
  2003-12-07T23:59:59

Without 'year' -

  $dti = DateTime::Incomplete->new( day=>7 );

  start:  undef 

  end:undef 

  span:   undef

  spanset:  DateTime::SpanSet =
  ...
  [ 2003-01-07T00:00:00 , 2003-01-08T00:00:00 )
  [ 2003-02-07T00:00:00 , 2003-02-08T00:00:00 )
  [ 2003-03-07T00:00:00 , 2003-03-08T00:00:00 )
  ...

  recurrence:  DateTime::Set =
  ...
  2003-01-07T00:00:00 ,
  2003-01-07T00:00:01 ,
  2003-01-07T00:00:02 ,
  ...
  2003-01-07T23:59:59 ,
  2003-02-07T00:00:00 ,
  ...


- Flavio S. Glock