File Coverage

blib/lib/DateTime/Infinite.pm
Criterion Covered Total %
statement 76 83 91.5
branch 5 6 83.3
condition 5 5 100.0
subroutine 38 45 84.4
pod 10 12 83.3
total 134 151 88.7


line stmt bran cond sub pod time code
1             ## no critic (Modules::ProhibitMultiplePackages)
2             package DateTime::Infinite;
3              
4 49     49   957 use strict;
  49         151  
  49         1768  
5 49     49   323 use warnings;
  49         183  
  49         1582  
6 49     49   319 use namespace::autoclean;
  49         119  
  49         527  
7              
8             our $VERSION = '1.61';
9              
10 49     49   4690 use DateTime;
  49         175  
  49         1238  
11 49     49   329 use DateTime::TimeZone;
  49         131  
  49         2995  
12              
13 49     49   361 use parent qw(DateTime);
  49         181  
  49         433  
14              
15             foreach my $m (qw( set set_time_zone truncate )) {
16             ## no critic (TestingAndDebugging::ProhibitNoStrict)
17 49     49   4024 no strict 'refs';
  49         1674  
  49         25417  
18 2     2   6 *{"DateTime::Infinite::$m"} = sub { return $_[0] };
19             }
20              
21 2     2 1 9 sub is_finite {0}
22 6     6 1 41 sub is_infinite {1}
23              
24             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
25             sub _rd2ymd {
26 98 50   98   625 return $_[2] ? ( $_[1] ) x 7 : ( $_[1] ) x 3;
27             }
28              
29             sub _seconds_as_components {
30 98     98   352 return ( $_[1] ) x 3;
31             }
32              
33             sub ymd {
34 2     2 1 15 return $_[0]->iso8601;
35             }
36              
37             sub mdy {
38 2     2 1 634 return $_[0]->iso8601;
39             }
40              
41             sub dmy {
42 2     2 1 657 return $_[0]->iso8601;
43             }
44              
45             sub hms {
46 4     4 1 623 return $_[0]->iso8601;
47             }
48              
49             sub hour_12 {
50 2     2 1 676 return $_[0]->_infinity_string;
51             }
52              
53             sub hour_12_0 {
54 2     2 1 615 return $_[0]->_infinity_string;
55             }
56              
57             sub datetime {
58 14     14 1 636 return $_[0]->_infinity_string;
59             }
60              
61             sub stringify {
62 2     2 1 326 return $_[0]->_infinity_string;
63             }
64              
65             sub _infinity_string {
66 20 100   20   226 return $_[0]->{utc_rd_days} == DateTime::INFINITY
67             ? DateTime::INFINITY . q{}
68             : DateTime::NEG_INFINITY . q{};
69             }
70              
71 2     2   12 sub _week_values { [ $_[0]->{utc_rd_days}, $_[0]->{utc_rd_days} ] }
72              
73 2     2 0 953 sub STORABLE_freeze {return}
74 0     0 0 0 sub STORABLE_thaw {return}
75              
76             package DateTime::Infinite::Future;
77              
78 49     49   396 use strict;
  49         125  
  49         1309  
79 49     49   316 use warnings;
  49         177  
  49         2199  
80              
81 49     49   364 use parent qw(DateTime::Infinite);
  49         134  
  49         251  
82              
83             {
84             my $Pos = bless {
85             utc_rd_days => DateTime::INFINITY,
86             utc_rd_secs => DateTime::INFINITY,
87             local_rd_days => DateTime::INFINITY,
88             local_rd_secs => DateTime::INFINITY,
89             rd_nanosecs => DateTime::INFINITY,
90             tz => DateTime::TimeZone->new( name => 'floating' ),
91             locale => FakeLocale->instance,
92             },
93             __PACKAGE__;
94              
95             $Pos->_calc_utc_rd;
96             $Pos->_calc_local_rd;
97              
98 4     4   529 sub new {$Pos}
99             }
100              
101             package DateTime::Infinite::Past;
102              
103 49     49   8320 use strict;
  49         110  
  49         1363  
104 49     49   266 use warnings;
  49         106  
  49         1697  
105              
106 49     49   292 use parent qw(DateTime::Infinite);
  49         131  
  49         276  
107              
108             {
109             my $Neg = bless {
110             utc_rd_days => DateTime::NEG_INFINITY,
111             utc_rd_secs => DateTime::NEG_INFINITY,
112             local_rd_days => DateTime::NEG_INFINITY,
113             local_rd_secs => DateTime::NEG_INFINITY,
114             rd_nanosecs => DateTime::NEG_INFINITY,
115             tz => DateTime::TimeZone->new( name => 'floating' ),
116             locale => FakeLocale->instance,
117             },
118             __PACKAGE__;
119              
120             $Neg->_calc_utc_rd;
121             $Neg->_calc_local_rd;
122              
123 4     4   709 sub new {$Neg}
124             }
125              
126             package # hide from PAUSE
127             FakeLocale;
128              
129 49     49   7724 use strict;
  49         121  
  49         1318  
130 49     49   275 use warnings;
  49         110  
  49         1600  
131              
132 49     49   307 use DateTime::Locale;
  49         125  
  49         8155  
133              
134             my $Instance;
135              
136             sub instance {
137 98   100 98   10165 return $Instance ||= bless { locale => DateTime::Locale->load('en_US') },
138             __PACKAGE__;
139             }
140              
141             sub id {
142 0     0   0 return 'infinite';
143             }
144              
145             sub language_id {
146 0     0   0 return 'infinite';
147             }
148              
149             sub name {
150 1     1   5 'Fake locale for Infinite DateTime objects';
151             }
152              
153             sub language {
154 0     0   0 'Fake locale for Infinite DateTime objects';
155             }
156              
157             my @methods = qw(
158             script_id
159             territory_id
160             variant_id
161             script
162             territory
163             variant
164             native_name
165             native_language
166             native_script
167             native_territory
168             native_variant
169             );
170              
171             for my $meth (@methods) {
172             ## no critic (TestingAndDebugging::ProhibitNoStrict)
173 49     49   355 no strict 'refs';
  49         114  
  49         12891  
174 0     0   0 *{$meth} = sub {undef};
175             }
176              
177             # Totally arbitrary
178             sub first_day_of_week {
179 0     0   0 return 1;
180             }
181              
182             sub prefers_24_hour_time {
183 0     0   0 return 0;
184             }
185              
186             our $AUTOLOAD;
187              
188             ## no critic (ClassHierarchies::ProhibitAutoloading)
189             sub AUTOLOAD {
190 5     5   1522 my $self = shift;
191              
192 5         35 my ($meth) = $AUTOLOAD =~ /::(\w+)$/;
193              
194 5 100 100     34 if ( $meth =~ /format/ && $meth !~ /^(?:day|month|quarter)/ ) {
195 1         20 return $self->{locale}->$meth(@_);
196             }
197              
198 4         34 return [];
199             }
200              
201             1;
202              
203             # ABSTRACT: Infinite past and future DateTime objects
204              
205             __END__
206              
207             =pod
208              
209             =encoding UTF-8
210              
211             =head1 NAME
212              
213             DateTime::Infinite - Infinite past and future DateTime objects
214              
215             =head1 VERSION
216              
217             version 1.61
218              
219             =head1 SYNOPSIS
220              
221             my $future = DateTime::Infinite::Future->new;
222             my $past = DateTime::Infinite::Past->new;
223              
224             =head1 DESCRIPTION
225              
226             This module provides two L<DateTime> subclasses, C<DateTime::Infinite::Future>
227             and C<DateTime::Infinite::Past>.
228              
229             The objects are always in the "floating" timezone, and this cannot be changed.
230              
231             =head1 METHODS
232              
233             The only constructor for these two classes is the C<new> method, as shown in
234             the L</SYNOPSIS>. This method takes no parameters.
235              
236             All "get" methods in this module simply return infinity, positive or negative.
237             If the method is expected to return a string, it returns the string
238             representation of positive or negative infinity used by your system. For
239             example, on my system calling C<< $dt->year >>> returns a number which when
240             printed appears either "Inf" or "-Inf".
241              
242             This also applies to methods that are compound stringifications, which return
243             the same strings even for things like C<< $dt->ymd >> or C<< $dt->iso8601 >>
244              
245             The object is not mutable, so the C<< $dt->set >>, C<< $dt->set_time_zone >>,
246             and C<< $dt->truncate >> methods are all do-nothing methods that simply return
247             the object they are called with.
248              
249             Obviously, the C<< $dt->is_finite >> method returns false and the C<<
250             $dt->is_infinite >> method returns true.
251              
252             =head1 SEE ALSO
253              
254             datetime@perl.org mailing list
255              
256             =head1 BUGS
257              
258             There seem to be lots of problems when dealing with infinite numbers on Win32.
259             This may be a problem with this code, Perl, or Win32's IEEE math
260             implementation. Either way, the module may not be well-behaved on Win32
261             operating systems.
262              
263             Bugs may be submitted at L<https://github.com/houseabsolute/DateTime.pm/issues>.
264              
265             There is a mailing list available for users of this distribution,
266             L<mailto:datetime@perl.org>.
267              
268             =head1 SOURCE
269              
270             The source code repository for DateTime can be found at L<https://github.com/houseabsolute/DateTime.pm>.
271              
272             =head1 AUTHOR
273              
274             Dave Rolsky <autarch@urth.org>
275              
276             =head1 COPYRIGHT AND LICENSE
277              
278             This software is Copyright (c) 2003 - 2023 by Dave Rolsky.
279              
280             This is free software, licensed under:
281              
282             The Artistic License 2.0 (GPL Compatible)
283              
284             The full text of the license can be found in the
285             F<LICENSE> file included with this distribution.
286              
287             =cut