Calendar-Slots

 view release on metacpan or  search on metacpan

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

	my $slot = shift;
	return $self->when eq $slot->when;	
}

sub ymd_hash {
    my $self = shift;
	my $when = $self->when;
    return (
        year  => substr( $when, 0, 4 ),
        month => substr( $when, 4, 2 ),
        day   => substr( $when, 6, 2 )
    );
}

sub reschedule {
    my $self = shift;
	my %args = @_;
	if( $self->type eq 'weekday' ) {
		if( my $days = $args{days} ) {
			my $weekday = $self->when + $days;
			$weekday = $weekday > 7 ? $weekday - 7 : $weekday;
			$self->when( $weekday );
		}
	} 
	else {
		my $dt = DateTime->new( $self->ymd_hash );
		$dt->add( %args );
		( my $when = $dt->ymd ) =~ s{/|\-}{}g;
		$self->when( $when );
	}
}

sub numeric {
    my $self = shift;
	if( $self->type eq 'date' ) {
		sprintf("%01d%08d%04d%04d", $self->weekday, 0, $self->start, $self->end );
	} else {
		sprintf("%01d%08d%04d%04d", $self->when, 0, $self->start, $self->end );
	}
}

1;
__END__

=pod

=head1 NAME

Calendar::Slots::Slot - the time-slot object

=head1 VERSION

version 0.15

=head1 SYNOPSIS

	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 );

=head1 METHODS

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

Returns true or false if the parameters match this time slot.

=head2 numeric

Returns a numeric rendition of the date and time parts, good for sorting.

=head2 weekday

Returns a weekday (1 to 7, Monday to Sunday). Works on both date or weekday 
slots.

=head2 reschedule( add=>Int )

Adds or subtract days to a slot. 

=head2 same_day

Compare two slots and return true if the day is the same. 

=head2 same_weekday( $slot )

Compare two slots and return true if the weekday is the same.

=head2 same_type

Compare two slots and return true if types match.

=head2 ymd_hash

Returns a hash suitable to feed to L<DateTime>:

	DateTime->new( $slot->ymd_hash );

=head1 AUTHOR

Rodrigo de Oliveira C<rodrigolive@gmail.com>

=head1 LICENSE

This library is free software. You can redistribute it and/or modify it under



( run in 1.073 second using v1.01-cache-2.11-cpan-5b529ec07f3 )