Calendar-Gregorian

 view release on metacpan or  search on metacpan

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

package Calendar::Gregorian;

$Calendar::Gregorian::VERSION   = '0.25';
$Calendar::Gregorian::AUTHORITY = 'cpan:MANWAR';

=head1 NAME

Calendar::Gregorian - Interface to Gregorian Calendar.

=head1 VERSION

Version 0.25

=cut

use 5.006;
use Data::Dumper;

use Date::Gregorian::Simple;
use Moo;
use namespace::autoclean;
use overload q{""} => 'as_string', fallback => 1;

has year  => (is => 'rw', predicate => 1);
has month => (is => 'rw', predicate => 1);
has date  => (is => 'ro', default   => sub { Date::Gregorian::Simple->new });
with 'Calendar::Plugin::Renderer';

sub BUILD {
    my ($self) = @_;

    $self->date->validate_year($self->year)   if $self->has_year;
    $self->date->validate_month($self->month) if $self->has_month;

    unless ($self->has_year && $self->has_month) {
        $self->year($self->date->year);
        $self->month($self->date->month);
    }
}

=head1 DESCRIPTION

Simple Gregorian Calendar interface.

    +-----------------------------------------------------------------------------------+
    |                                  March [2016 BE]                                  |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |    Sunday |    Monday |   Tuesday | Wednesday |  Thursday |    Friday |  Saturday |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |                       |         1 |         2 |         3 |         4 |         5 |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |         6 |         7 |         8 |         9 |        10 |        11 |        12 |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |        13 |        14 |        15 |        16 |        17 |        18 |        19 |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |        20 |        21 |        22 |        23 |        24 |        25 |        26 |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+
    |        27 |        28 |        29 |        30 |        31 |                       |
    +-----------+-----------+-----------+-----------+-----------+-----------+-----------+

The package L<App::calendr> provides command line tool  C<calendr> to display the
supported calendars on the terminal.

=head1 SYNOPSIS

    use strict; use warnings;
    use Calendar::Gregorian;

    # prints current gregorian month calendar.
    print Calendar::Gregorian->new, "\n";
    print Calendar::Gregorian->new->current, "\n";

    # prints gregorian month calendar for the first month of year 2016.
    print Calendar::Gregorian->new({ month => 1, year => 2016 }), "\n";

    # prints gregorian month calendar in which the given julian date falls in.
    print Calendar::Gregorian->new->from_julian(2457102.5), "\n";

    # prints current month gregorian calendar in SVG format.
    print Calendar::Gregorian->new->as_svg;



( run in 0.550 second using v1.01-cache-2.11-cpan-5a3173703d6 )