line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package perl5i::0::DateTime; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# A file to contain the Datetime work for perl5i to get it out of perl5i.pm |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
31
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
7
|
1
|
|
|
1
|
|
15
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
6
|
use Time::y2038; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
732
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitSubroutinePrototypes) |
12
|
|
|
|
|
|
|
sub dt_gmtime (;$) { |
13
|
0
|
0
|
|
0
|
0
|
|
my $time = @_ ? shift : time; |
14
|
0
|
0
|
|
|
|
|
return gmtime($time) if wantarray; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
|
my($sec, $min, $hour, $mday, $mon, $year) = gmtime($time); |
17
|
0
|
|
|
|
|
|
$mon++; |
18
|
0
|
|
|
|
|
|
$year += 1900; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
require DateTime; |
21
|
0
|
|
|
|
|
|
return perl5i::0::DateTime::y2038->new( |
22
|
|
|
|
|
|
|
year => $year, |
23
|
|
|
|
|
|
|
month => $mon, |
24
|
|
|
|
|
|
|
day => $mday, |
25
|
|
|
|
|
|
|
hour => $hour, |
26
|
|
|
|
|
|
|
minute => $min, |
27
|
|
|
|
|
|
|
second => $sec, |
28
|
|
|
|
|
|
|
formatter => "perl5i::0::DateTime::Format::CTime" |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitSubroutinePrototypes) |
34
|
|
|
|
|
|
|
sub dt_localtime (;$) { |
35
|
0
|
0
|
|
0
|
0
|
|
my $time = @_ ? shift : time; |
36
|
0
|
0
|
|
|
|
|
return localtime($time) if wantarray; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my($sec, $min, $hour, $mday, $mon, $year) = localtime($time); |
39
|
0
|
|
|
|
|
|
$mon++; |
40
|
0
|
|
|
|
|
|
$year += 1900; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
require DateTime; |
43
|
0
|
|
|
|
|
|
return perl5i::0::DateTime::y2038->new( |
44
|
|
|
|
|
|
|
year => $year, |
45
|
|
|
|
|
|
|
month => $mon, |
46
|
|
|
|
|
|
|
day => $mday, |
47
|
|
|
|
|
|
|
hour => $hour, |
48
|
|
|
|
|
|
|
minute => $min, |
49
|
|
|
|
|
|
|
second => $sec, |
50
|
|
|
|
|
|
|
time_zone => "local", |
51
|
|
|
|
|
|
|
formatter => "perl5i::0::DateTime::Format::CTime" |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitSubroutinePrototypes) |
57
|
|
|
|
|
|
|
sub dt_time () { |
58
|
0
|
|
|
0
|
0
|
|
require DateTime::Format::Epoch; |
59
|
0
|
|
|
|
|
|
state $formatter = DateTime::Format::Epoch->new( epoch => DateTime->from_epoch( epoch => 0 ) ); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
require DateTime; |
62
|
0
|
|
|
|
|
|
return perl5i::0::DateTime::time->from_epoch( |
63
|
|
|
|
|
|
|
epoch => time, |
64
|
|
|
|
|
|
|
formatter => $formatter |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
package perl5i::0::DateTime::y2038; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Don't load DateTime until we need it. |
73
|
|
|
|
|
|
|
our @ISA = qw(DateTime); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use overload |
76
|
|
|
|
|
|
|
"eq" => sub { |
77
|
0
|
|
|
0
|
|
0
|
my($dt1, $dt2) = @_; |
78
|
0
|
0
|
|
|
|
0
|
return "$dt1" eq "$dt2" if !eval { $dt2->isa("DateTime") }; |
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
|
|
0
|
return $dt1 eq $dt2; |
80
|
1
|
|
|
1
|
|
7
|
}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub from_epoch { |
83
|
0
|
|
|
0
|
|
|
my $class = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
require Time::y2038; |
86
|
1
|
|
|
1
|
|
102
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
257
|
|
87
|
0
|
|
|
|
|
|
local *CORE::GLOBAL::gmtime = \&Time::y2038::gmtime; |
88
|
0
|
|
|
|
|
|
local *CORE::GLOBAL::localtime = \&Time::y2038::localtime; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $class->SUPER::from_epoch(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Copy of DateTime's own epoch() function. |
95
|
|
|
|
|
|
|
sub epoch { |
96
|
0
|
|
|
0
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $zone = $self->time_zone; |
99
|
0
|
|
|
|
|
|
$self->set_time_zone("UTC"); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
require Time::y2038; |
102
|
0
|
|
|
|
|
|
my $time = Time::y2038::timegm( |
103
|
|
|
|
|
|
|
$self->sec, $self->min, $self->hour, $self->mday, |
104
|
|
|
|
|
|
|
$self->mon - 1, |
105
|
|
|
|
|
|
|
$self->year - 1900, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$self->set_time_zone($zone); |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $time; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
{ |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
package perl5i::0::DateTime::time; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
1
|
|
1114
|
use parent -norequire, qw(perl5i::0::DateTime::y2038); |
|
1
|
|
|
|
|
444
|
|
|
1
|
|
|
|
|
7
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
use overload |
121
|
0
|
|
|
0
|
|
0
|
"0+" => sub { $_[0]->epoch }, |
122
|
|
|
|
|
|
|
"-" => sub { |
123
|
0
|
|
|
0
|
|
0
|
my( $a, $b, $reverse ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
0
|
if($reverse) { |
126
|
0
|
|
|
|
|
0
|
( $b, $a ) = ( $a, $b ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
0
|
my $time_a = eval { $a->isa("DateTime") } ? $a->epoch : $a; |
|
0
|
|
|
|
|
0
|
|
130
|
0
|
0
|
|
|
|
0
|
my $time_b = eval { $b->isa("DateTime") } ? $b->epoch : $b; |
|
0
|
|
|
|
|
0
|
|
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
0
|
return $time_a - $time_b; |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
"+" => sub { |
136
|
0
|
|
|
0
|
|
0
|
my( $a, $b, $reverse ) = @_; |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
0
|
if($reverse) { |
139
|
0
|
|
|
|
|
0
|
( $b, $a ) = ( $a, $b ); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
0
|
my $time_a = eval { $a->isa("DateTime") } ? $a->epoch : $a; |
|
0
|
|
|
|
|
0
|
|
143
|
0
|
0
|
|
|
|
0
|
my $time_b = eval { $b->isa("DateTime") } ? $b->epoch : $b; |
|
0
|
|
|
|
|
0
|
|
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
0
|
return $time_a + $time_b; |
146
|
|
|
|
|
|
|
}, |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
"==" => sub { |
149
|
0
|
|
|
0
|
|
0
|
my($a, $b) = @_; |
150
|
0
|
0
|
|
|
|
0
|
return $a+0 == $b+0 if !eval { $b->isa("DateTime") }; |
|
0
|
|
|
|
|
0
|
|
151
|
0
|
|
|
|
|
0
|
return $a == $b; |
152
|
|
|
|
|
|
|
}, |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
1
|
|
301
|
fallback => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
package perl5i::0::DateTime::Format::CTime; |
161
|
|
|
|
|
|
|
|
162
|
1
|
|
|
1
|
|
878
|
use CLASS; |
|
1
|
|
|
|
|
313
|
|
|
1
|
|
|
|
|
5
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub new { |
165
|
0
|
|
|
0
|
|
|
return bless {}, $CLASS; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub format_datetime { |
169
|
0
|
|
|
0
|
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
my $dt = shift; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# Straight from the Open Group asctime() docs. |
173
|
0
|
|
|
|
|
|
return sprintf "%.3s %.3s%3d %.2d:%.2d:%.2d %d", |
174
|
|
|
|
|
|
|
$dt->day_abbr, |
175
|
|
|
|
|
|
|
$dt->month_abbr, |
176
|
|
|
|
|
|
|
$dt->mday, |
177
|
|
|
|
|
|
|
$dt->hour, |
178
|
|
|
|
|
|
|
$dt->min, |
179
|
|
|
|
|
|
|
$dt->sec, |
180
|
|
|
|
|
|
|
$dt->year, |
181
|
|
|
|
|
|
|
; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |