| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Date::Easy::Date; |
|
2
|
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
89
|
use strict; |
|
|
15
|
|
|
|
|
21
|
|
|
|
15
|
|
|
|
|
374
|
|
|
4
|
15
|
|
|
15
|
|
63
|
use warnings; |
|
|
15
|
|
|
|
|
22
|
|
|
|
15
|
|
|
|
|
296
|
|
|
5
|
15
|
|
|
15
|
|
60
|
use autodie; |
|
|
15
|
|
|
|
|
20
|
|
|
|
15
|
|
|
|
|
61
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.09_01'; # TRIAL VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
15
|
|
|
15
|
|
63915
|
use Exporter; |
|
|
15
|
|
|
|
|
28
|
|
|
|
15
|
|
|
|
|
625
|
|
|
10
|
15
|
|
|
15
|
|
91
|
use parent 'Exporter'; |
|
|
15
|
|
|
|
|
25
|
|
|
|
15
|
|
|
|
|
67
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw< date today >; |
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( all => \@EXPORT_OK ); |
|
13
|
|
|
|
|
|
|
|
|
14
|
15
|
|
|
15
|
|
1499
|
use parent 'Date::Easy::Datetime'; |
|
|
15
|
|
|
|
|
24
|
|
|
|
15
|
|
|
|
|
62
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
15
|
|
|
15
|
|
609
|
use Carp; |
|
|
15
|
|
|
|
|
25
|
|
|
|
15
|
|
|
|
|
663
|
|
|
17
|
15
|
|
|
15
|
|
74
|
use Scalar::Util 'blessed'; |
|
|
15
|
|
|
|
|
19
|
|
|
|
15
|
|
|
|
|
517
|
|
|
18
|
15
|
|
|
15
|
|
66
|
use Time::Local 1.26, qw< timegm_modern >; |
|
|
15
|
|
|
|
|
20
|
|
|
|
15
|
|
|
|
|
13177
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
############################## |
|
22
|
|
|
|
|
|
|
# FUNCTIONS (*NOT* METHODS!) # |
|
23
|
|
|
|
|
|
|
############################## |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub date |
|
27
|
|
|
|
|
|
|
{ |
|
28
|
277
|
|
|
277
|
1
|
290429
|
my $date = shift; |
|
29
|
277
|
100
|
|
|
|
1599
|
if ( $date =~ /^-?\d+$/ ) |
|
|
|
100
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
{ |
|
31
|
13
|
100
|
100
|
|
|
62
|
if ($date < 29000000 and $date >= 10000000) |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
6
|
|
|
|
|
42
|
my @time = $date =~ /^(\d{4})(\d{2})(\d{2})$/; |
|
34
|
6
|
|
|
|
|
22
|
return Date::Easy::Date->new(@time); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
7
|
|
|
|
|
27
|
return Date::Easy::Date->new($date); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
elsif ( $date !~ /\d/ ) |
|
39
|
|
|
|
|
|
|
{ |
|
40
|
19
|
|
|
|
|
43
|
my $time = _parsedate($date); |
|
41
|
19
|
100
|
|
|
|
6878
|
croak("Illegal date: $date") unless defined $time; |
|
42
|
18
|
|
|
|
|
48
|
return Date::Easy::Date->new($time); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
else |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
245
|
|
|
|
|
689
|
my (undef,undef,undef, $d, $m, $y) # ignore first 3 values (time portion) |
|
47
|
|
|
|
|
|
|
= Date::Easy::Datetime::_strptime($date, 'local'); # remember: parse as local, store as UTC |
|
48
|
245
|
100
|
|
|
|
464
|
if (defined $y) # they're either all defined, or it's bogus |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
|
|
|
|
|
|
# return value from _strptime for month is still in the funky 0 - 11 range |
|
51
|
153
|
|
|
|
|
436
|
return Date::Easy::Date->new($y, $m + 1, $d); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
else |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
92
|
|
|
|
|
212
|
my $time = _parsedate($date); |
|
56
|
92
|
100
|
|
|
|
22629
|
croak("Illegal date: $date") unless defined $time; |
|
57
|
75
|
|
|
|
|
195
|
return Date::Easy::Date->new($time); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
0
|
|
|
|
|
0
|
die("reached unreachable code"); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
5
|
|
|
5
|
1
|
2575
|
sub today () { Date::Easy::Date->new } |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _parsedate |
|
67
|
|
|
|
|
|
|
{ |
|
68
|
111
|
|
|
111
|
|
1117
|
require Time::ParseDate; |
|
69
|
111
|
|
|
|
|
8532
|
my $string = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Remove any timezone specifier so we get the date as it was in that timezone. |
|
72
|
|
|
|
|
|
|
# I've gathered up all timezone matching code from Time::ParseDate as of v2015.103. |
|
73
|
|
|
|
|
|
|
# matching code from Time/ParseDate.pm: |
|
74
|
111
|
|
|
|
|
262
|
my $break = qr{(?:\s+|\Z|\b(?![-:.,/]\d))}; # line 67 |
|
75
|
111
|
|
|
|
|
1241
|
$string =~ s/ |
|
76
|
|
|
|
|
|
|
(?: |
|
77
|
|
|
|
|
|
|
[+-] \d\d:?\d\d \s+ \( "? (?: [A-Z]{1,4}[TCW56] | IDLE ) \) # lines 424-435 |
|
78
|
|
|
|
|
|
|
| GMT \s* [-+]\d{1,2} # line 441 |
|
79
|
|
|
|
|
|
|
| (?: GMT \s* )? [+-] \d\d:?\d\d # line 452 |
|
80
|
|
|
|
|
|
|
| "? (?: [A-Z]{1,4}[TCW56] | IDLE ) # line 457 (and 695-700) |
|
81
|
|
|
|
|
|
|
) $break //x; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# We *must* force scalar context. Remember, parsedate called in list context also returns the |
|
84
|
|
|
|
|
|
|
# "remainder" of the parsed string (which is often undef, which could wreak havoc with a call |
|
85
|
|
|
|
|
|
|
# that incorporates our return value, particularly one to _mktime). |
|
86
|
111
|
|
|
|
|
274
|
return scalar Time::ParseDate::parsedate($string, DATE_REQUIRED => 1); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
####################### |
|
91
|
|
|
|
|
|
|
# REGULAR CLASS STUFF # |
|
92
|
|
|
|
|
|
|
####################### |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
2121
|
|
|
2121
|
1
|
143284
|
my $class = shift; |
|
98
|
2121
|
|
|
|
|
2768
|
my ($y, $m, $d); |
|
99
|
2121
|
100
|
|
|
|
3828
|
if (@_ == 3) |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
275
|
|
|
|
|
465
|
($y, $m, $d) = @_; |
|
102
|
275
|
|
|
|
|
321
|
--$m; # timegm will expect month as 0..11 |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
else |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
1846
|
|
|
|
|
2480
|
my ($time) = @_; |
|
107
|
1846
|
100
|
|
|
|
3091
|
$time = time unless defined $time; |
|
108
|
1846
|
100
|
|
|
|
4745
|
if (my $conv_class = blessed $time) |
|
109
|
|
|
|
|
|
|
{ |
|
110
|
1739
|
100
|
|
|
|
3841
|
if ( $time->isa('Time::Piece') ) |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
1737
|
|
|
|
|
3314
|
($d, $m, $y) = ($time->mday, $time->_mon, $time->year); |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
else |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
2
|
|
|
|
|
21
|
croak("Don't know how to convert $conv_class to $class"); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
else |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
107
|
|
|
|
|
1439
|
($d, $m, $y) = (localtime $time)[3..5]; # `Date`s are parsed relative to local time ... |
|
122
|
107
|
|
|
|
|
332
|
$y += 1900; # (no 2-digit dates allowed!) |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
my $truncated_date = |
|
127
|
2119
|
|
|
|
|
16873
|
eval { timegm_modern( 0,0,0, $d,$m,$y ) }; # ... but stored as UTC |
|
|
2119
|
|
|
|
|
4583
|
|
|
128
|
2119
|
100
|
|
|
|
56377
|
croak("Illegal date: $y/" . ($m + 1) . "/$d") unless defined $truncated_date; |
|
129
|
2116
|
|
|
|
|
3976
|
return $class->_mkdate($truncated_date); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _mkdate |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
2116
|
|
|
2116
|
|
3192
|
my ($invocant, $epoch) = @_; |
|
135
|
2116
|
|
33
|
|
|
5628
|
my $class = ref $invocant || $invocant; |
|
136
|
2116
|
|
|
|
|
4896
|
return bless Date::Easy::Datetime->new(UTC => $epoch), $class; # always UTC |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
############################ |
|
141
|
|
|
|
|
|
|
# OVERRIDDEN FROM DATETIME # |
|
142
|
|
|
|
|
|
|
############################ |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub split |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
1
|
|
|
1
|
1
|
512
|
my $impl = shift->{impl}; |
|
148
|
1
|
|
|
|
|
4
|
( $impl->year, $impl->mon, $impl->mday ) |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# override addition and subtraction |
|
153
|
|
|
|
|
|
|
# numbers added to a ::Date are days |
|
154
|
|
|
|
|
|
|
|
|
155
|
978
|
|
|
978
|
|
1897
|
sub _add_integer { $_[0]->add_days($_[1]) } |
|
156
|
246
|
|
|
246
|
|
435
|
sub _subtract_integer { $_[0]->subtract_days($_[1]) } |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# These are illegal to call. |
|
160
|
2
|
|
|
2
|
1
|
390
|
sub add_seconds { die("cannot call add_seconds on a Date value") } |
|
161
|
2
|
|
|
2
|
1
|
306
|
sub add_minutes { die("cannot call add_minutes on a Date value") } |
|
162
|
2
|
|
|
2
|
1
|
300
|
sub add_hours { die("cannot call add_hours on a Date value") } |
|
163
|
2
|
|
|
2
|
1
|
335
|
sub subtract_seconds { die("cannot call subtract_seconds on a Date value") } |
|
164
|
2
|
|
|
2
|
1
|
317
|
sub subtract_minutes { die("cannot call subtract_minutes on a Date value") } |
|
165
|
2
|
|
|
2
|
1
|
301
|
sub subtract_hours { die("cannot call subtract_hours on a Date value") } |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# ABSTRACT: easy date class |
|
174
|
|
|
|
|
|
|
# COPYRIGHT |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |