Calendar-Slots

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

---
abstract: 'Create calendars with reserved slots'
author:
  - 'Rodrigo de Oliveira <rodrigolive@gmail.com>'
build_requires: {}
configure_requires:
  ExtUtils::MakeMaker: 6.30
dynamic_config: 0
generated_by: 'Dist::Zilla version 4.300021, CPAN::Meta::Converter version 2.120921'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

Makefile.PL  view on Meta::CPAN

use strict;
use warnings;



use ExtUtils::MakeMaker 6.30;



my %WriteMakefileArgs = (
  "ABSTRACT" => "Create calendars with reserved slots",
  "AUTHOR" => "Rodrigo de Oliveira <rodrigolive\@gmail.com>",
  "BUILD_REQUIRES" => {},
  "CONFIGURE_REQUIRES" => {
    "ExtUtils::MakeMaker" => "6.30"
  },
  "DISTNAME" => "Calendar-Slots",
  "EXE_FILES" => [],
  "LICENSE" => "perl",
  "NAME" => "Calendar::Slots",
  "PREREQ_PM" => {

README  view on Meta::CPAN



This archive contains the distribution Calendar-Slots,
version 0.15:

  Create calendars with reserved slots

This software is copyright (c) 2012 by Rodrigo de Oliveira.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.


dist.ini  view on Meta::CPAN

name    = Calendar-Slots
version = 0.15
abstract = Create calendars with reserved slots
license = Perl_5
author  = Rodrigo de Oliveira <rodrigolive@gmail.com>
copyright_holder = Rodrigo de Oliveira

[@Classic]

[Prereq]
Moose          = 0
namespace::autoclean = 0
Moose::Util::TypeConstraints = 0

lib/Calendar/Slots.pm  view on Meta::CPAN

=head1 SYNOPSIS

	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'

=head1 DESCRIPTION

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. 

=head1 LIMITATIONS

Some of it current limitations:

=over

=item * No overlapping of time slots. 

lib/Calendar/Slots.pm  view on Meta::CPAN

=item * It does not handle timezones.

=item * It does not know of daylight-savings or any other DateTime features.

=back

=head1 METHODS

=head2 slot ( name=>Str, { date=>'YYYY-MM-DD' | weekday=>1..7 | start_date/end_date }, start=>'HH:MM', end=>'HH:MM' )

Add a time slot to the calendar.

If the new time slot overlaps an existing slot with the same C<name>, 
the slots are merged and become a single slot. 

If the new time slot overlaps an existing slot with a different C<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' ); 

=head2 find ( { date=>'YYYY-MM-DD' | weekday=>1..7 }, time=>'HH:MM' )

Returns a L<Calendar::Slots::Slot> object for a given .

	$cal->find( weekday=>1, time=>'11:30' );   # find what's on Monday at 11:30

=head2 name 

Shortcut method to L<find|/find> a slot and return a name. 

=head2 sorted 

Returns a  ARRAY of all slot objects in the calendar.

=head2 materialize ( start_date, end_date ) 

Returns an instance of L<Calendar::Slots> with
date slots converted into weekdays for a given
date range.

    my $new_cal = $cal->materialize( 2012_10_22, 2012_10_28 );

=head2 week_of ( date ) 

Returns a materialized instance of L<Calendar::Slots> with actual 
dates merged for the week that comprises 
the passed C<date>.  

    my $week = $cal->week_of( 2012_10_22 );
    $week->find( weekday=>2, time=>10_30 );  # ...

=head2 all 

Returns an ARRAY of all slot objects in the calendar.

=head2 as_table

Returns a console string as a table for the calendar.

Requires that L<Data::Format::Pretty::Console> be installed.

    print $cal->as_table;

=head1 SEE ALSO

L<DateTime::SpanSet>

=head1 TODO

There are many improvements planned for this module, as this is just 
an ALPHA release that allows me to get somethings done at $work...

=over

=item * Other types of recurrence: first Monday, last Friday of September...

=item * Merge several calendars into one.

=item * Create subclasses of Calendar::Slots::Slot for each slot type. 

=item * Better input formatting based on DateTime objects and the such.

=head1 AUTHOR

Rodrigo de Oliveira C<rodrigolive@gmail.com>

=head1 LICENSE

lib/Calendar/Slots/Slot.pm  view on Meta::CPAN

	use Calendar::Slots::Slot;
	my $slot = new Calendar::Slots::Slot( date=>'2009-10-22', start=>'20:30', end=>'22:30', name=>'birthday' ); 
	print
		$slot->contains( date=>'2009-10-22', time=>'21:00' )
		? 'I'm busy'
		: 'I'm free then';


=head1 DESCRIPTION

This is the basic class defining a calendar slot. 

=head1 ATTRIBUTES

    has name    => ( is => 'rw', isa => 'Str' );
    has data    => ( is => 'rw', isa => 'Any' );
    has when    => ( is => 'rw', isa => 'Int', required=>1, );
    has start   => ( is => 'rw', isa => 'Int' );
    has end     => ( is => 'rw', isa => 'Int' );
    has type    => ( is => 'rw', isa => 'Str', required=>1 );



( run in 0.659 second using v1.01-cache-2.11-cpan-c333fce770f )