OurCal::Day - a representation of a day in OurCal


OurCal documentation Contained in the OurCal distribution.

Index


Code Index:

NAME

Top

OurCal::Day - a representation of a day in OurCal

SYNOPSIS

Top

    my $day = OurCal::Day->new( date => "2007-11-12");

METHODS

Top

day_of_week

What day of the week it is (Monday is 1, Sunday is 7)

day_of_month

What day of the month it is

is_first_day_of_month

IS this the first day of the month

is_last_day_of_month

Is this the last day of the month.

is_this_span

Calls is_today

is_today

Returns whether or not this is today in the real world.

month

Returns the month object this belongs to.

has_events

Returns whether this day has events.

events

Returns the events for this day.

as_string

Returns this day as a string

as_long_string

Returns the day as a long, wordy, almost, dare I say it, verbose string.

prev

Returns the previous day.

next

Returns the next day


OurCal documentation Contained in the OurCal distribution.
package OurCal::Day;

use strict;
use OurCal::Event;
use Lingua::EN::Numbers::Ordinate;
use base qw(OurCal::Span);


sub day_of_week {
    my $self = shift;
    return $self->{_dt}->strftime("%u");
}

sub day_of_month {
    my $self = shift;
    return $self->{_dt}->strftime("%d");
}

sub is_first_day_of_month {
    my $self = shift;
    # TODO did I do this for a clever reason or can I not just check 
    # that day_of_month == 1
    return $self->{_dt}->month != 
           $self->{_dt}->clone->subtract( days => 1)->month;
}

sub is_last_day_of_month {
    my $self = shift;
    return $self->{_dt}->month != 
           $self->{_dt}->clone->add( days => 1)->month;
}

sub is_this_span {
    my $self = shift;
    return $self->is_today;
}

sub is_today {
    my $self = shift;
    my $now  = DateTime->now->truncate( to => 'day' );
    return $now == $self->{_dt};
}

sub month {
    my $self = shift;
    my $date = $self->{_dt}->clone->truncate( to => 'month')->strftime("%Y-%m");
    return $self->_span("OurCal::Month", $date);
}

sub has_events {
    my $self = shift;
    my $cal  = $self->calendar;
    return $cal->has_events( date => $self->date );
}

sub events {
    my $self = shift;
    my $cal  = $self->calendar;
    return $cal->events( date => $self->date );
}
   

sub as_string {
    my $self = shift;
    my $day = ordinate($self->{_dt}->day());
    return $self->{_dt}->strftime("%d/%m");
}


sub as_long_string {
    my $self = shift;
    my $day = ordinate($self->{_dt}->day());
    return $self->{_dt}->strftime("%A the $day of %B, %Y");
}

sub prev {
    my $self = shift;
    return $self->_shift($self->{_dt}->clone->subtract( days => 1 )->strftime("%Y-%m-%d"));
}

sub next {
    my $self = shift;
    return $self->_shift($self->{_dt}->clone->add( days => 1 )->strftime("%Y-%m-%d"));
}

1;