Dan Kubb wrote:
> I recently worked on a project where I had to keep track of data
> that changed over time. I needed to keep a history of the
> changes, as well as allow values to be specified for future
> time periods.
> For example, a value could be set, and it would go into
> effect starting now. A second value could be set that
> goes into effect in 2 weeks, and expires 2 weeks after
> that.. after which time, the original value goes back
> into effect.
# snip
> I'm certainly open to suggestions, or criticism on the code or
> interface. I'm not even sure this belongs under the DateTime
> namespace, but I figured this was the best place to start asking.
G'day Dan,
Thanks for your interest. A couple of things ...
1. You need to put it somewhere further under the namespace. Such as
DateTime::Event::Temporal?
2. This sounds very similar to the Calendaring system I'm working on ...
I just hadn't thought of this sort of event. Currently when two events
clash, one disappears while the other remains. Or one of them moves to
some open time. However your event replaces only the intersecting
portions. This sort of event will help in other places too.
Also, DateTime::Event::Calendar can store a value with an event, and can
even happily store a reference such as a hashref so there's no problem
retrieving your value.
Here's some example code:
$calendar = DateTime::Event::Calendar->new('Temporal Value');
$calendar->register(
behaviour => 'blockout', # not a good name, still thinking
event => DateTime::Event::Calendar::Event->from_span(
start => $dt1,
end => $dt2,
),
data => '1',
}
$calendar->register(
behaviour => 'blockout',
event => DateTime::Event::Calendar::Event->from_span(
start => $dt3,
end => $dt4,
),
data => '2',
}
__END__
So it's all in there now. Given dt3 and dt4 fall between dt1 and dt2,
here's what we have:
dt1 dt3 dt4 dt2
|-------^-------^---^-----^-----|
And as we travel through the calendar, $calendar->current_event->data
returns:
| 1111111122222111111 |
Which I believe is the result you need?
Cheers!
Rick Measham