line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mango::BSON::Time; |
2
|
11
|
|
|
11
|
|
74
|
use Mojo::Base -base; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
68
|
|
3
|
11
|
|
|
11
|
|
2101
|
use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1; |
|
11
|
|
|
7
|
|
29
|
|
|
11
|
|
|
0
|
|
168
|
|
|
0
|
|
|
|
|
0
|
|
|
7
|
|
|
|
|
419
|
|
4
|
|
|
|
|
|
|
|
5
|
11
|
|
|
11
|
|
5933
|
use Mojo::Date; |
|
11
|
|
|
|
|
44793
|
|
|
11
|
|
|
|
|
118
|
|
6
|
11
|
|
|
11
|
|
484
|
use Time::HiRes 'time'; |
|
11
|
|
|
|
|
38
|
|
|
11
|
|
|
|
|
105
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
66
|
14
|
1
|
77
|
sub new { shift->SUPER::new(time => shift // int(time * 1000)) } |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
1
|
110
|
sub TO_JSON { 0 + shift->{time} } |
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
1
|
29
|
sub to_datetime { Mojo::Date->new->epoch(shift->to_epoch)->to_datetime } |
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
1
|
47
|
sub to_epoch { shift->to_string / 1000 } |
15
|
|
|
|
|
|
|
|
16
|
13
|
|
|
13
|
1
|
148
|
sub to_string { shift->{time} } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
1; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding utf8 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Mango::BSON::Time - Datetime type |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Mango::BSON::Time; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $time = Mango::BSON::Time->new(time * 1000); |
31
|
|
|
|
|
|
|
say $time->to_epoch; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
L is a container for the BSON datetime type used by |
36
|
|
|
|
|
|
|
L. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
L inherits all methods from L and implements |
41
|
|
|
|
|
|
|
the following new ones. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 new |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $time = Mango::BSON::Time->new; |
46
|
|
|
|
|
|
|
my $time = Mango::BSON::Time->new(time * 1000); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Construct a new L object. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 TO_JSON |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $num = $time->TO_JSON; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Numeric representation of time. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 to_datetime |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $str = $time->to_datetime; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Convert time to L date and time. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 to_epoch |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $epoch = $time->to_epoch; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Convert time to floating seconds since the epoch. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 to_string |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $str = $time->to_string; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Stringify time. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 OPERATORS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L overloads the following operators. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 bool |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $bool = !!$time; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Always true. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 stringify |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $str = "$time"; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Alias for L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SEE ALSO |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L, L, L. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |