DateTime::Infinite - Infinite past and future DateTime objects


DateTime documentation Contained in the DateTime distribution.

Index


Code Index:

NAME

Top

DateTime::Infinite - Infinite past and future DateTime objects

VERSION

Top

version 0.70

SYNOPSIS

Top

  my $future = DateTime::Infinite::Future->new();
  my $past   = DateTime::Infinite::Past->new();

DESCRIPTION

Top

This module provides two DateTime.pm subclasses, DateTime::Infinite::Future and DateTime::Infinite::Past.

The objects are in the "floating" timezone, and this cannot be changed.

BUGS

Top

There seem to be lots of problems when dealing with infinite numbers on Win32. This may be a problem with this code, Perl, or Win32's IEEE math implementation. Either way, the module may not be well-behaved on Win32 operating systems.

METHODS

Top

The only constructor for these two classes is the new() method, as shown in the SYNOPSIS. This method takes no parameters.

All "get" methods in this module simply return infinity, positive or negative. If the method is expected to return a string, it return the string representation of positive or negative infinity used by your system. For example, on my system calling year() returns a number which when printed appears either "inf" or "-inf".

The object is not mutable, so the set(), set_time_zone(), and truncate() methods are all do-nothing methods that simply return the object they are called with.

Obviously, the is_finite() method returns false and the is_infinite() method returns true.

SEE ALSO

Top

datetime@perl.org mailing list

http://datetime.perl.org/

AUTHOR

Top

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE

Top


DateTime documentation Contained in the DateTime distribution.

package DateTime::Infinite;
BEGIN {
  $DateTime::Infinite::VERSION = '0.70';
}

use strict;
use warnings;

use DateTime;
use DateTime::TimeZone;

use base qw(DateTime);

foreach my $m (qw( set set_time_zone truncate )) {
    no strict 'refs';
    *{"DateTime::Infinite::$m"} = sub { return $_[0] };
}

sub is_finite   {0}
sub is_infinite {1}

sub _rd2ymd {
    return $_[2] ? ( $_[1] ) x 7 : ( $_[1] ) x 3;
}

sub _seconds_as_components {
    return ( $_[1] ) x 3;
}

sub _stringify {
    $_[0]->{utc_rd_days} == DateTime::INFINITY
        ? DateTime::INFINITY . ''
        : DateTime::NEG_INFINITY . '';
}

sub STORABLE_freeze {return}
sub STORABLE_thaw   {return}

package DateTime::Infinite::Future;
BEGIN {
  $DateTime::Infinite::Future::VERSION = '0.70';
}

use base qw(DateTime::Infinite);

{
    my $Pos = bless {
        utc_rd_days   => DateTime::INFINITY,
        utc_rd_secs   => DateTime::INFINITY,
        local_rd_days => DateTime::INFINITY,
        local_rd_secs => DateTime::INFINITY,
        rd_nanosecs   => DateTime::INFINITY,
        tz            => DateTime::TimeZone->new( name => 'floating' ),
        },
        __PACKAGE__;

    $Pos->_calc_utc_rd;
    $Pos->_calc_local_rd;

    sub new {$Pos}
}

package DateTime::Infinite::Past;
BEGIN {
  $DateTime::Infinite::Past::VERSION = '0.70';
}

use base qw(DateTime::Infinite);

{
    my $Neg = bless {
        utc_rd_days   => DateTime::NEG_INFINITY,
        utc_rd_secs   => DateTime::NEG_INFINITY,
        local_rd_days => DateTime::NEG_INFINITY,
        local_rd_secs => DateTime::NEG_INFINITY,
        rd_nanosecs   => DateTime::NEG_INFINITY,
        tz            => DateTime::TimeZone->new( name => 'floating' ),
        },
        __PACKAGE__;

    $Neg->_calc_utc_rd;
    $Neg->_calc_local_rd;

    sub new {$Neg}
}

1;

# ABSTRACT: Infinite past and future DateTime objects




__END__