DT

 view release on metacpan or  search on metacpan

lib/DT.pm  view on Meta::CPAN

    my $dt;

    if ( @_ == 1 ) {
        # Most probably Unix time, will croak if not
        if ( looks_like_number $_[0] ) {
            $dt = $class->SUPER::new(@_);
        }
        elsif ( not ref $_[0] ) {
            # May be ISO8601(ish) format used by PostgreSQL
            $dt = eval {
                $HAVE_PG || ($HAVE_PG = require DateTime::Format::Pg);
                DateTime::Format::Pg->parse_datetime($_[0]);
            };
            

            # May be a real ISO8601 format date/time
            $dt = eval { DateTime::Format::ISO8601->parse_datetime($_[0]) }
                if not $dt;
        }
    }

lib/DT.pm  view on Meta::CPAN

    $dt = DateTime->new(@_) unless $dt;

    # Rebless into DT so our methods are called instead of DateTime
    return bless $dt, $class;
}

sub unix_time { $_[0]->epoch }

sub pg_timestamp_notz {
    Carp::croak("DateTime::Format::Pg is not installed")
        unless $HAVE_PG || ($HAVE_PG = require DateTime::Format::Pg);
    
    return DateTime::Format::Pg->format_timestamp_without_time_zone($_[0]);
}

sub pg_timestamp_tz {
    Carp::croak("DateTime::Format::Pg is not installed")
        unless $HAVE_PG || ($HAVE_PG = require DateTime::Format::Pg);
    
    return DateTime::Format::Pg->format_timestamptz($_[0]);
}

{
    for my $method (qw(
        add_duration subtract_duration
        truncate
        set set_time_zone set_year set_month set_day
        set_hour set_minute set_second set_nanosecond



( run in 0.250 second using v1.01-cache-2.11-cpan-0d8aa00de5b )