line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Moment; |
2
|
24
|
|
|
24
|
|
1795066
|
use strict; |
|
24
|
|
|
|
|
229
|
|
|
24
|
|
|
|
|
661
|
|
3
|
24
|
|
|
24
|
|
111
|
use warnings; |
|
24
|
|
|
|
|
45
|
|
|
24
|
|
|
|
|
625
|
|
4
|
|
|
|
|
|
|
|
5
|
24
|
|
|
24
|
|
117
|
use Carp qw[]; |
|
24
|
|
|
|
|
44
|
|
|
24
|
|
|
|
|
1173
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
BEGIN { |
8
|
24
|
|
|
24
|
|
83
|
our $VERSION = '0.44'; |
9
|
24
|
|
|
|
|
133
|
require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); |
|
24
|
|
|
|
|
20327
|
|
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
13
|
24
|
50
|
|
24
|
|
826
|
unless (exists &Time::Moment::now) { |
14
|
0
|
|
|
|
|
0
|
require Time::HiRes; |
15
|
0
|
|
|
|
|
0
|
eval sprintf <<'EOC', __FILE__; |
16
|
|
|
|
|
|
|
# line 17 %s |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# expects normalized tm values; algorithm is only valid for tm year's [1, 199] |
19
|
|
|
|
|
|
|
sub timegm { |
20
|
|
|
|
|
|
|
my ($y, $d, $h, $m, $s) = @_[5,7,2,1,0]; |
21
|
|
|
|
|
|
|
return ((1461 * --$y >> 2) + $d - 25202) * 86400 + $h * 3600 + $m * 60 + $s; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub now { |
25
|
|
|
|
|
|
|
@_ == 1 || Carp::croak(q/Usage: Time::Moment->now()/); |
26
|
|
|
|
|
|
|
my ($class) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my ($sec, $usec) = Time::HiRes::gettimeofday(); |
29
|
|
|
|
|
|
|
my $offset = int((timegm(localtime($sec)) - $sec) / 60); |
30
|
|
|
|
|
|
|
return $class->from_epoch($sec, $usec * 1000) |
31
|
|
|
|
|
|
|
->with_offset_same_instant($offset); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub now_utc { |
35
|
|
|
|
|
|
|
@_ == 1 || Carp::croak(q/Usage: Time::Moment->now_utc()/); |
36
|
|
|
|
|
|
|
my ($class) = @_; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my ($sec, $usec) = Time::HiRes::gettimeofday(); |
39
|
|
|
|
|
|
|
return $class->from_epoch($sec, $usec * 1000); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
EOC |
42
|
0
|
0
|
|
|
|
0
|
die $@ if $@; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
BEGIN { |
47
|
24
|
|
|
24
|
|
14010
|
delete @Time::Moment::{qw(timegm)}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub __as_DateTime { |
51
|
0
|
|
|
0
|
|
0
|
my ($tm) = @_; |
52
|
0
|
|
|
|
|
0
|
return DateTime->from_epoch( |
53
|
|
|
|
|
|
|
epoch => $tm->epoch, |
54
|
|
|
|
|
|
|
time_zone => $tm->strftime('%Z'), |
55
|
|
|
|
|
|
|
)->set_nanosecond($tm->nanosecond); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub __as_Time_Piece { |
59
|
0
|
|
|
0
|
|
0
|
my ($tm) = @_; |
60
|
0
|
|
|
|
|
0
|
return scalar Time::Piece::gmtime($tm->epoch); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub DateTime::__as_Time_Moment { |
64
|
0
|
|
|
0
|
|
0
|
my ($dt) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
0
|
(!$dt->time_zone->is_floating) |
67
|
|
|
|
|
|
|
or Carp::croak(q/Cannot coerce an instance of DateTime in the 'floating' / |
68
|
|
|
|
|
|
|
.q/time zone to an instance of Time::Moment/); |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
return Time::Moment->from_epoch($dt->epoch, $dt->nanosecond) |
71
|
|
|
|
|
|
|
->with_offset_same_instant(int($dt->offset / 60)); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub Time::Piece::__as_Time_Moment { |
75
|
2
|
|
|
2
|
|
3432
|
my ($tp) = @_; |
76
|
2
|
|
|
|
|
12
|
return Time::Moment->from_epoch($tp->epoch) |
77
|
|
|
|
|
|
|
->with_offset_same_instant(int($tp->tzoffset / 60)); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub STORABLE_freeze { |
81
|
3
|
|
|
3
|
0
|
2238
|
my ($self, $cloning) = @_; |
82
|
3
|
100
|
|
|
|
38
|
return if $cloning; |
83
|
2
|
|
|
|
|
93
|
return pack 'nnNNN', 0x544D, $self->offset, $self->utc_rd_values; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub STORABLE_thaw { |
87
|
2
|
|
|
2
|
0
|
789
|
my ($self, $cloning, $packed) = @_; |
88
|
2
|
50
|
|
|
|
5
|
return if $cloning; |
89
|
2
|
50
|
33
|
|
|
12
|
(length($packed) == 16 && vec($packed, 0, 16) == 0x544D) # TM |
90
|
|
|
|
|
|
|
or die(q/Cannot deserialize corrupted data/); # Don't replace die with Carp! |
91
|
2
|
|
|
|
|
9
|
my ($offset, $rdn, $sod, $nos) = unpack 'xxnNNN', $packed; |
92
|
2
|
100
|
|
|
|
5
|
$offset = ($offset & 0x7FFF) - 0x8000 if ($offset & 0x8000); |
93
|
2
|
|
|
|
|
5
|
my $seconds = ($rdn - 719163) * 86400 + $sod; |
94
|
2
|
|
|
|
|
2
|
$$self = ${ ref($self)->from_epoch($seconds, $nos) |
|
2
|
|
|
|
|
60
|
|
95
|
|
|
|
|
|
|
->with_offset_same_instant($offset) }; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub TO_JSON { |
99
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->to_string; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub TO_CBOR { |
103
|
|
|
|
|
|
|
# Use the standard tag for date/time string; see RFC 7049 Section 2.4.1 |
104
|
0
|
|
|
0
|
0
|
0
|
return CBOR::XS::tag(0, $_[0]->to_string); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub FREEZE { |
108
|
2
|
|
|
2
|
1
|
236
|
return $_[0]->to_string; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub THAW { |
112
|
2
|
|
|
2
|
1
|
450
|
my ($class, undef, $string) = @_; |
113
|
2
|
|
|
|
|
29
|
return $class->from_string($string); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Alias |
117
|
|
|
|
|
|
|
*with_offset = \&with_offset_same_instant; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# used by DateTime::TimeZone |
120
|
|
|
|
|
|
|
sub utc_year { |
121
|
0
|
|
|
0
|
0
|
|
return $_[0]->with_offset_same_instant(0)->year; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|