Hill, Ronald wrote:
> > > sub daytime_as_spanset {
> > > my $self = shift;
> > > my $class = ref($self);
> > > my $sunrises = $self->sunrise_as_set;
> > > my $sunsets = $self->sunset_as_set;
> > > return $sunrises->until( $sunsets );
> > > }
>
> maybe sunrise_as_spanset? (land of the midnight sun)
Mmm. What does sunrise returns when you don't have nights?
I suppose it would be 00:00 ?
Anyway, it would return something like:
... [2003-03-28 06:00 until 2003-03-28 19:00),
[2003-03-29 06:03 until 2003-03-29 19:03),
[2003-03-30 06:06 until 2003-03-30 19:09), ...
> > >
> > > sub nighttime_as_spanset {
> > > my $self = shift;
> > > my $class = ref($self);
> > > my $sunrises = $self->sunrise_as_set;
> > > my $sunsets = $self->sunset_as_set;
> > > return $sunsets->until( $sunrises );
> > > }
> > >
> sunset_as_spanset?
This one would return the nights:
... [2003-03-28 19:00 until 2003-03-29 06:03),
[2003-03-29 19:03 until 2003-03-30 06:06) ...
> > > > my $easter = $easter_sunday->as_set(from=>$dt1, to=>$dt2,
> > inclusive=>1);
> > >
> > > # I would expect $easter_sunday->as_spanset to return
> > > # the time from sunday 00:00 until 23:59
> > > $easter = $easter_sunday->as_spanset->intersection( $dt_span );
>
> This is what is throwing me for a loop. The easter_sunday method
> is returning a date (year,month,day) with no time information
> because it does not matter what time it is. Weather it is
> noon or 3:00PM it is still easter!
The idea is that easter_sunday->as_set would return "start-of-event"
info:
... 2003-04-28 ,
2004-04-28 ...
(these are not real easter sundays, just an example)
(these are actually daytimes with 00:00:00 h/m/s)
While easter_sunday->as_spanset would return "whole days", as spans:
... [2003-04-28 00:00 until 2003-04-29 00:00),
[2004-04-28 00:00 until 2004-04-29 00:00) ...
> > > my $set2 = $sunrise->daytime_as_spanset->intersection ( $easter );
>
> This took my some time to understand because of the term intersection.
> When I see this I think of union, intersection in terms of arrays ie:
> finding union of arrays intersection (differences) of arrays. However,
> in context of your module, it means a while loop. This may need some
> clarification in the documentation/examples.
Intersection is what is in _both_ sets, like:
A = ( 1, 3, 5, 7 )
B = ( 1, 5, 9, 12 )
A intersection B = ( 1, 5 )
In datetime context, we would get "sunrise until sunset, on easter
sundays":
"daytime spans"
... [2003-03-28 06:00 until 2003-03-28 19:00),
[2003-03-29 06:03 until 2003-03-29 19:03),
[2003-03-30 06:06 until 2003-03-30 19:09), ...
"intersection" to "easter sunday spans":
... [2003-04-28 00:00 until 2003-04-29 00:00),
[2004-04-28 00:00 until 2004-04-29 00:00) ...
gives:
... [2003-04-28 06:12 until 2003-04-29 19:12),
[2004-04-28 06:12 until 2004-04-29 19:12) ...
It could save some programming :)
> I hope this helps,
Sure! Thanks. I'll try to improve the docs in DateTime::Set now.
- Flavio S. Glock