Calendar::Slots - Manage time slots
use Calendar::Slots; my $cal = new Calendar::Slots; $cal->slot( date=>'2009-10-11', start=>'10:30', end=>'11:30', name=>'busy' ); my $slot = $cal->find( date=>'2009-10-11', time=>'11:00' ); print $slot->name; # 'busy'
This is a simple module to manage a calendar of very generic time slots. Time slots are anything with a start and end time on a given date or weekday. Time slots cannot overlap. If a new time slot overlaps another pre-existing time slot, the calendar will acommodate the slot automatically.
It handles two types of slots: fixed dates, or recurring on weekdays. When looking for an event, it will search from most specific (date) to more generic (recurring). That is, if a slot exist for both a date and a weekday, it returns the date slot only.
The calendar is able to compact itself and generate rows that can be easily stored in a file or database.
Some of it current limitations:
Add a time slot to the calendar.
If the new time slot overlaps an existing slot with the same
name, the slots are merged and become a single slot.
If the new time slot overlaps an existing slot with a different
name, it overwrites the previous slot, splitting it if necessary.
my $cal = Calendar::Slots->new; # reserve that monday slot $cal->slot( date=>'2009-11-30', start=>'10:30', end=>'11:00', name=>'doctor appointment' ); # create a time slot for a given date $cal->slot( date=>'2009-01-01', start=>'10:30', end=>'24:00' ); # create a recurring time slot over 3 calendar days $cal->slot( start_date=>'2009-01-01', end_date=>'2009-02-01', start=>'10:30', end=>'24:00' );
Returns a Calendar::Slots::Slot object for a given .
$cal->find( weekday=>1, time=>'11:30' ); # find what's on Monday at 11:30
Shortcut method to find a slot and return a name.
Returns a ARRAY of all slot objects in the calendar.
Returns an instance of Calendar::Slots with date slots converted into weekdays for a given date range.
my $new_cal = $cal->materialize( 2012_10_22, 2012_10_28 );
Returns a materialized instance of Calendar::Slots with actual dates merged for the week that comprises the passed
my $week = $cal->week_of( 2012_10_22 ); $week->find( weekday=>2, time=>10_30 ); # ...
Returns an ARRAY of all slot objects in the calendar.
Returns a console string as a table for the calendar.
Requires that Data::Format::Pretty::Console be installed.
There are many improvements planned for this module, as this is just an ALPHA release that allows me to get somethings done at $work...
Rodrigo de Oliveira
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.