Commit | Line | Data |
3fea05b9 |
1 | package DateTime::Infinite; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | our $VERSION = '0.53'; |
7 | |
8 | use DateTime; |
9 | use DateTime::TimeZone; |
10 | |
11 | use base qw(DateTime); |
12 | |
13 | foreach my $m ( qw( set set_time_zone truncate ) ) |
14 | { |
15 | no strict 'refs'; |
16 | *{"DateTime::Infinite::$m"} = |
17 | sub { return $_[0] }; |
18 | } |
19 | |
20 | sub is_finite { 0 } |
21 | sub is_infinite { 1 } |
22 | |
23 | sub _rd2ymd |
24 | { |
25 | return $_[2] ? ($_[1]) x 7 : ($_[1]) x 3; |
26 | } |
27 | |
28 | sub _seconds_as_components |
29 | { |
30 | return ($_[1]) x 3; |
31 | } |
32 | |
33 | sub _stringify { ( $_[0]->{utc_rd_days} == DateTime::INFINITY |
34 | ? DateTime::INFINITY . '' |
35 | : DateTime::NEG_INFINITY . '' |
36 | ) } |
37 | |
38 | sub STORABLE_freeze { return } |
39 | sub STORABLE_thaw { return } |
40 | |
41 | package DateTime::Infinite::Future; |
42 | |
43 | use base qw(DateTime::Infinite); |
44 | |
45 | { |
46 | my $Pos = bless { utc_rd_days => DateTime::INFINITY, |
47 | utc_rd_secs => DateTime::INFINITY, |
48 | local_rd_days => DateTime::INFINITY, |
49 | local_rd_secs => DateTime::INFINITY, |
50 | rd_nanosecs => DateTime::INFINITY, |
51 | tz => DateTime::TimeZone->new( name => 'floating' ), |
52 | }, __PACKAGE__; |
53 | |
54 | $Pos->_calc_utc_rd; |
55 | $Pos->_calc_local_rd; |
56 | |
57 | sub new { $Pos } |
58 | } |
59 | |
60 | package DateTime::Infinite::Past; |
61 | |
62 | use base qw(DateTime::Infinite); |
63 | |
64 | { |
65 | my $Neg = bless { utc_rd_days => DateTime::NEG_INFINITY, |
66 | utc_rd_secs => DateTime::NEG_INFINITY, |
67 | local_rd_days => DateTime::NEG_INFINITY, |
68 | local_rd_secs => DateTime::NEG_INFINITY, |
69 | rd_nanosecs => DateTime::NEG_INFINITY, |
70 | tz => DateTime::TimeZone->new( name => 'floating' ), |
71 | }, __PACKAGE__; |
72 | |
73 | $Neg->_calc_utc_rd; |
74 | $Neg->_calc_local_rd; |
75 | |
76 | sub new { $Neg } |
77 | } |
78 | |
79 | |
80 | 1; |
81 | |
82 | __END__ |
83 | |
84 | =head1 NAME |
85 | |
86 | DateTime::Infinite - Infinite past and future DateTime objects |
87 | |
88 | =head1 SYNOPSIS |
89 | |
90 | my $future = DateTime::Infinite::Future->new; |
91 | my $past = DateTime::Infinite::Past->new; |
92 | |
93 | =head1 DESCRIPTION |
94 | |
95 | This module provides two L<DateTime.pm|DateTime> subclasses, |
96 | C<DateTime::Infinite::Future> and C<DateTime::Infinite::Past>. |
97 | |
98 | The objects are in the "floating" timezone, and this cannot be |
99 | changed. |
100 | |
101 | =head1 BUGS |
102 | |
103 | There seem to be lots of problems when dealing with infinite numbers |
104 | on Win32. This may be a problem with this code, Perl, or Win32's IEEE |
105 | math implementation. Either way, the module may not be well-behaved |
106 | on Win32 operating systems. |
107 | |
108 | =head1 METHODS |
109 | |
110 | The only constructor for these two classes is the C<new()> method, as |
111 | shown in the L<SYNOPSIS|/SYNOPSIS>. This method takes no parameters. |
112 | |
113 | All "get" methods in this module simply return infinity, positive or |
114 | negative. If the method is expected to return a string, it return the |
115 | string representation of positive or negative infinity used by your |
116 | system. For example, on my system calling C<year()> returns a number |
117 | which when printed appears either "inf" or "-inf". |
118 | |
119 | The object is not mutable, so the C<set()>, C<set_time_zone()>, and |
120 | C<truncate()> methods are all do-nothing methods that simply return |
121 | the object they are called with. |
122 | |
123 | Obviously, the C<is_finite()> method returns false and the |
124 | C<is_infinite()> method returns true. |
125 | |
126 | =head1 AUTHOR |
127 | |
128 | Dave Rolsky <autarch@urth.org> |
129 | |
130 | =head1 COPYRIGHT |
131 | |
132 | Copyright (c) 2003-2009 David Rolsky. All rights reserved. This |
133 | program is free software; you can redistribute it and/or modify it |
134 | under the same terms as Perl itself. |
135 | |
136 | The full text of the license can be found in the LICENSE file included |
137 | with this module. |
138 | |
139 | =head1 SEE ALSO |
140 | |
141 | datetime@perl.org mailing list |
142 | |
143 | http://datetime.perl.org/ |
144 | |
145 | =cut |
146 | |