DateTime-Format-Natural

 view release on metacpan or  search on metacpan

lib/DateTime/Format/Natural/Calc.pm  view on Meta::CPAN

    my ($year, $month, $day) = do {
        @_ >= 3 ? @_ : (undef, @_);
    };
    $year ||= $self->{datetime}->year;
    unless (defined $day) {
        $day = $self->_Days_in_Month($year, $month);
    }
    $self->_set(
        year  => $year,
        month => $month,
        day   => $day,
    );
}

sub _variant_last_month
{
    my $self = shift;
    $self->_register_trace;
    my $opts = pop;
    my ($day) = @_;
    $self->_subtract(month => 1);
    unless (defined $day) {
        $day = $self->_Days_in_Month($self->{datetime}->year, $self->{datetime}->month);
    }
    $self->_set(day => $day);
}

sub _variant_quarter
{
    my $self = shift;
    $self->_register_trace;
    my $opts = pop;
    my ($when) = @_;
    $self->_subtract(day => $self->{datetime}->day_of_quarter - 1);
    $self->_add_or_subtract({
        when  => $when,
        unit  => $opts->{unit},
        value => 3,
    });
}

sub _begin_end_month
{
    my $self = shift;
    $self->_register_trace;
    my $opts = pop;
    my ($day) = @_;
    unless (defined $day) {
        $day = $self->_Days_in_Month($self->{datetime}->year, $self->{datetime}->month);
    }
    $self->_set(day => $day);
}

sub _christmas_new_year
{
    my $self = shift;
    $self->_register_trace;
    my $opts = pop;
    my ($when) = @_;
    my %holidays = %{$self->{data}->{holidays}};
    my $calendar = DateTime::Format::Natural::Calendar::_init($self->{Calendar_class});
    my $year = $self->{datetime}->year;
    my ($month, $day) = @{$holidays{$calendar->{type}}{$opts->{type}}}{qw(month day)};
    $self->{datetime}->set(hour => 0, minute => 0, second => 0, nanosecond => 0);
    my $code = sub
    {
        my ($year, $month, $day, $opts) = @_;
        $$year++ if $opts->{type} eq 'new_year';
    };
    if ($calendar->_can_convert) {
        ($year, $month, $day) = $calendar->_to_gregorian($year, $month, $day, $opts, $code);
    }
    else {
        $code->(\$year, \$month, \$day, $opts);
    }
    $self->_set(
        year  => $year,
        month => $month,
        day   => $day,
    );
    $self->_add_or_subtract({
        when  => $when,
        unit  => 'hour',
        value => 4,
    });
}

1;
__END__

=head1 NAME

DateTime::Format::Natural::Calc - Basic calculations

=head1 SYNOPSIS

 Please see the DateTime::Format::Natural documentation.

=head1 DESCRIPTION

The C<DateTime::Format::Natural::Calc> class defines the worker methods.

=head1 SEE ALSO

L<DateTime::Format::Natural>

=head1 AUTHOR

Steven Schubiger <schubiger@cpan.org>

=head1 LICENSE

This program is free software; you may redistribute it and/or
modify it under the same terms as Perl itself.

See L<http://dev.perl.org/licenses/>

=cut



( run in 1.210 second using v1.01-cache-2.11-cpan-f52f0507bed )