DateTime

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

There are many other modules that work with DateTime, including modules in the
[DateTimeX namespace](https://metacpan.org/search?q=datetimex) namespace, as
well as others.

See [MetaCPAN](https://metacpan.org/search?q=datetime) for more modules.

# KNOWN BUGS

The tests in `20infinite.t` seem to fail on some machines, particularly on
Win32. This appears to be related to Perl's internal handling of IEEE infinity
and NaN, and seems to be highly platform/compiler/phase of moon dependent.

If you don't plan to use infinite datetimes you can probably ignore this. This
will be fixed (perhaps) in future versions.

# SEE ALSO

[A Date with Perl](http://presentations.houseabsolute.com/a-date-with-perl/) -
a talk I've given at a few YAPCs.

[datetime@perl.org mailing list](http://lists.perl.org/list/datetime.html)

lib/DateTime.pm  view on Meta::CPAN

    sub add_duration {
        my $self = shift;
        my ($dur) = $validator->(@_);

        # simple optimization
        return $self if $dur->is_zero;

        my %deltas = $dur->deltas;

        # This bit isn't quite right since DateTime::Infinite::Future -
        # infinite duration should NaN
        for my $val ( values %deltas ) {
            my $inf;
            if ( $val == INFINITY ) {
                $inf = DateTime::Infinite::Future->new;
            }
            elsif ( $val == NEG_INFINITY ) {
                $inf = DateTime::Infinite::Past->new;
            }

            if ($inf) {

lib/DateTime.pm  view on Meta::CPAN

There are many other modules that work with DateTime, including modules in the
L<DateTimeX namespace|https://metacpan.org/search?q=datetimex> namespace, as
well as others.

See L<MetaCPAN|https://metacpan.org/search?q=datetime> for more modules.

=head1 KNOWN BUGS

The tests in F<20infinite.t> seem to fail on some machines, particularly on
Win32. This appears to be related to Perl's internal handling of IEEE infinity
and NaN, and seems to be highly platform/compiler/phase of moon dependent.

If you don't plan to use infinite datetimes you can probably ignore this. This
will be fixed (perhaps) in future versions.

=head1 SEE ALSO

L<A Date with Perl|http://presentations.houseabsolute.com/a-date-with-perl/> -
a talk I've given at a few YAPCs.

L<datetime@perl.org mailing list|http://lists.perl.org/list/datetime.html>

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


sub MAX_NANOSECONDS () {1_000_000_000}    # 1E9 = almost 32 bits

my @all_units = qw( months days minutes seconds nanoseconds );

{
    my %units = map {
        $_ => {

            # XXX - what we really want is to accept an integer, Inf, -Inf,
            # and NaN, but I can't figure out how to accept NaN since it never
            # compares to anything.
            type    => t('Defined'),
            default => 0,
        }
        } qw(
        years
        months
        weeks
        days
        hours

ppport.h  view on Meta::CPAN

    s++; if (s == send || (*s != 'F' && *s != 'f')) return 0;
    s++; if (s < send && (*s == 'I' || *s == 'i')) {
      s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
      s++; if (s == send || (*s != 'I' && *s != 'i')) return 0;
      s++; if (s == send || (*s != 'T' && *s != 't')) return 0;
      s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0;
      s++;
    }
    sawinf = 1;
  } else if (*s == 'N' || *s == 'n') {
    /* XXX TODO: There are signaling NaNs and quiet NaNs. */
    s++; if (s == send || (*s != 'A' && *s != 'a')) return 0;
    s++; if (s == send || (*s != 'N' && *s != 'n')) return 0;
    s++;
    sawnan = 1;
  } else
    return 0;

  if (sawinf) {
    numtype &= IS_NUMBER_NEG; /* Keep track of sign  */
    numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT;

t/20infinite.t  view on Meta::CPAN

    ok(
        $neg2 == $neg,
        'normal + neg infinite duration = neg infinity'
    );

    my $dur     = $pos - $pos;
    my %deltas  = $dur->deltas;
    my @compare = qw( days seconds nanoseconds );
    foreach (@compare) {

        # NaN != NaN (but should stringify the same)
        is(
            $deltas{$_} . q{}, $nan_string,
            "infinity - infinity = nan ($_)"
        );
    }

    my $new_pos = $pos->clone->add( days => 10 );
    ok(
        $new_pos == $pos,
        'infinity + normal duration = infinity'

xt/author/pp-20infinite.t  view on Meta::CPAN

    ok(
        $neg2 == $neg,
        'normal + neg infinite duration = neg infinity'
    );

    my $dur     = $pos - $pos;
    my %deltas  = $dur->deltas;
    my @compare = qw( days seconds nanoseconds );
    foreach (@compare) {

        # NaN != NaN (but should stringify the same)
        is(
            $deltas{$_} . q{}, $nan_string,
            "infinity - infinity = nan ($_)"
        );
    }

    my $new_pos = $pos->clone->add( days => 10 );
    ok(
        $new_pos == $pos,
        'infinity + normal duration = infinity'



( run in 0.432 second using v1.01-cache-2.11-cpan-4d50c553e7e )