develooper Front page | perl.datetime | Postings from January 2003

Date sets

From:
fglock
Date:
January 13, 2003 05:26
Subject:
Date sets
Message ID:
3E22BEE5.4E9@pucrs.br
Dave Rolsky wrote: 
> how an infinite set could be a base date object.

A 'one-element-set' behaves just like a 'datetime'.

> I want the timezone code to just represent a timezone (an entry in the
> Olsen db), not a date _with_ a timezone.  The DateTime class will _use_
> the DateTime::TimeZone class.  They won't _be_ the same thing. 

It is possible to make a separate class for timezones, in order to make
the API clearer. 
Internally, however, the code converts everything to sets.
See the example below.

> I just took a look at Set::Infinite.  To be blunt, the code's a bit of a
> mess.  The methods are _way_ too big.  

There are a lot of optimizations - it could be reduced to 1/3 of the
size without them.
Otimized code is much more difficult to test and read.
I'd like to have some help with it, of course.

> is there a reference I could look at somewhere?  

Sorry, there is no reference except the PODs. 
Date::Set POD is a little better than Set::Infinite's.
I just tried Google, but it didn't help much.

> What's the difference between Set::Infinite::Date and Date::Set?

If you think of Set::Infinite as a 'tree' object, 
then Set::Infinite::Date is a 'leaf' object.
(I wrote Set::Infinite::Date before I entered the Reefknot project)

Date::Set is a 'tree' of Date::ICal 'leaves'.
Date::Set::ICal is an internal class that interfaces Date::Set to
Date::ICal.

----
This is an example modified from Date::Set::Timezone t/timezone.t. 
A 'Olsen' timezone is specified and applied, with only
Date::Set::Timezone methods.
----

  # creates a set of UTC times for testing
  $set = Date::Set::Timezone->new( 
    '20030105Z', '20030107Z',    # before DST
    '20030205Z', '20030315Z',    # DST begins
    '20030405Z', '20030410Z',    # inside DST
    '20030505Z', '20030701Z',    # DST ends
  );
  # check if tz_change() changes timezone and dst properly
  is ( ''.$set->tz_change( {
    dst => Date::Set::Timezone->
              dtstart( start => '20010105T020000Z' )->
              event( rule=>'FREQ=YEARLY;BYMONTH=3' )
         ->until( Date::Set::Timezone->
              dtstart( start => '20010105T020000Z' )->
              event( rule=>'FREQ=YEARLY;BYMONTH=6' ) ) ,
    name =>   ['', 'dst'] ,
    offset => [ 2*3600, 1*3600 ] ,
  } ),
    '[20030105T020000..20030107T020000],'.
    '[20030205T020000..20030315T010000 dst],'.
    '[20030405T010000 dst..20030410T010000 dst],'.
    '[20030505T010000 dst..20030701T020000]',
    'timezone specified by unbounded recurrences' );

----

- Flávio S. Glock



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About