DateTime-Lite

 view release on metacpan or  search on metacpan

lib/DateTime/Lite.pm  view on Meta::CPAN

    {
        %new = (
            year       => $self->year,
            month      => int( ( $self->month - 1 ) / 3 ) * 3 + 1,
            day        => 1,
            hour       => 0,
            minute     => 0,
            second     => 0,
            nanosecond => 0,
        );
    }
    else
    {
        my $truncate = 0;
        foreach my $f ( qw( year month day hour minute second nanosecond ) )
        {
            $new{$f} = $truncate ? $TruncateDefault{$f} : $self->$f();
            $truncate = 1 if( $p{to} eq $f );
        }
    }

    if( %new )
    {
        my $new_dt = $self->_new_from_self( %new, _skip_validation => 1 ) || return( $self->pass_error );
        %$self = %$new_dt;
    }

    return( $self );
}

sub utc_rd_as_seconds
{
    my $self = shift( @_ );
    return( $self->{utc_rd_days} * SECONDS_PER_DAY + $self->{utc_rd_secs} );
}

sub utc_rd_values
{
    my $self = shift( @_ );
    return( $self->{utc_rd_days}, $self->{utc_rd_secs}, $self->{rd_nanosecs} );
}

sub utc_year { $_[0]->{utc_year} }

sub week
{
    my $self = shift( @_ );

    # Memoised: computing week values requires day_of_year and day_of_week
    # which are already in local_c, so this is cheap after the first call.
    unless( exists( $self->{utc_c}->{week_year} ) )
    {
        $self->{utc_c}->{week_year} = $self->_week_values;
    }
    return( @{$self->{utc_c}->{week_year}}[0, 1] );
}

sub week_number { ( $_[0]->week )[1] }

# ISO: first week of the month is the first week containing a Thursday.
# Direct formula - no clone, no add(), no recursion.
# NOTE: week_of_month is autoloaded

sub week_year { ( $_[0]->week )[0] }

# NOTE: weekday_of_month is autoloaded

sub year
{
    my $self = shift( @_ );
    return( $self->{local_c}->{year} );
}

# NOTE: year_length is autoloaded

# NOTE: year_with_christian_era is autoloaded

# NOTE: year_with_era is autoloaded

# NOTE: year_with_secular_era is autoloaded

sub ymd
{
    my $self = shift( @_ );
    my $sep  = defined( $_[0] ) ? shift( @_ ) : '-';
    return( sprintf( "%04d%s%02d%s%02d",
        $self->year, $sep, $self->month, $sep, $self->day ) );
}

# NOTE:: AUTOLOAD
sub AUTOLOAD
{
    my $self;
    $self = shift( @_ ) if( Scalar::Util::blessed( $_[0] ) && $_[0]->isa( 'DateTime::Lite' ) );
    my( $class, $meth );
    $class = ref( $self ) || $self;
    no overloading;
    no strict 'refs';
    $meth = $AUTOLOAD;
    if( CORE::index( $meth, '::' ) != -1 )
    {
        my $idx = rindex( $meth, '::' );
        $class = substr( $meth, 0, $idx );
        $meth  = substr( $meth, $idx + 2 );
    }

    unless( $AUTOLOAD_SUBS )
    {
        &_autoload_subs();
    }
    my $code;
    if( CORE::exists( $AUTOLOAD_SUBS->{ $meth } ) )
    {
        $code = $AUTOLOAD_SUBS->{ $meth };
        my $saved = $@;
        local $@;
        {
            no strict;
            eval( $code );
        }
        if( $@ )



( run in 1.748 second using v1.01-cache-2.11-cpan-df04353d9ac )