jdtoronto has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

A project of mine has just grown out of control, well for a few minutes, I am sure I can tame it!

I have been asked to add a flexible appointment system to it. So I have figured out that I need:

  1. For each service provider a DB table of DOW with start and finish times for the periods avilable for appointment.
  2. An exception table for each (what holidays don't i work and what days so I just want to take off).
  3. An altered availability table that allows the provider to change available hours within a given day or period.
OK, having that data I need to then calculate the actual times during the time period for the appointment book. The intervals need to be flexible - lets say in one minute increments.

So I would need to be able to ask: Give me a list of times between start and end in x minute intervals so that I can populate an HTML table.

Any suggestions as to modules to use? I am only familiar with Date::Manip so far.

jdtoronto

  • Comment on Calculating clock time within a period.

Replies are listed 'Best First'.
Re: Calculating clock time within a period.
by Fletch (Bishop) on Jan 09, 2004 at 17:46 UTC

    Erm, given start and end as time_t values (use Date::Parse or whatever to get them there) just convert your interval into seconds and add.

    sub intervals { my( $start, $end, $interval ) = @_; my @ret; my $cur = $start; while( $cur <= $end ) { push @ret, $cur; $cur += $interval; } return @ret }
Re: Calculating clock time within a period.
by duff (Parson) on Jan 09, 2004 at 19:31 UTC

    There is bound to be something useful in the DateTime module set. But you can also implement this yourself with some judicious use of gmtime() and Time::Local.

    As an aside, you might be interested in the Reefknot project.

Re: Calculating clock time within a period.
by fglock (Vicar) on Jan 10, 2004 at 03:51 UTC

    I can't test this right now, but I hope it will give you a start:

    use strict; use DateTime::Span; use DateTime::Event::Recurrence; my $set1 = DateTime::Event::Recurrence->minutely( interval => 30 ); my $date1 = DateTime->new( year => 2002, month => 3, day => 11 ); my $date2 = DateTime->new( year => 2003, month => 3, day => 12 ); my $set2 = DateTime::Span->from_datetimes( start => $date1, end => $date2 ); my @dt = $set1->intersection( $set2 ); for ( @dt ) { print $_->datetime, "\n"; }