| 1 | package Mango::BSON::Time; | ||||||||||||
| 2 | 11 | ▶ | use Mojo::Base -base; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 0 | ▶ | use overload bool => sub {1}, '""' => sub { shift->to_string }, fallback => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: not called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=1 SCAR=0.1
| |||||||||||||
| 4 | |||||||||||||
| 5 | 11 | ▶ | use Mojo::Date; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 11 | ▶ | use Time::HiRes 'time'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 14 | ▶ | sub new { shift->SUPER::new(time => shift // int(time * 1000)) } | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
shift() // int &Mango::BSON::Time::time() * 1000
MC/DC100%1/1
shift() // int &Mango::BSON::Time::time() * 1000
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | sub TO_JSON { 0 + shift->{time} } | ||||||||||
|
Subroutine
TO_JSON: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | sub to_datetime { Mojo::Date->new->epoch(shift->to_epoch)->to_datetime } | ||||||||||
|
Subroutine
to_datetime: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 13 | |||||||||||||
| 14 | 6 | ▶ | sub to_epoch { shift->to_string / 1000 } | ||||||||||
|
Subroutine
to_epoch: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 15 | |||||||||||||
| 16 | 13 | ▶ | sub to_string { shift->{time} } | ||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 17 | |||||||||||||
| 18 | 11 | 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<Mango::BSON::Time> is a container for the BSON datetime type used by | ||||||||||||
| 36 | L<Mango::BSON>. | ||||||||||||
| 37 | |||||||||||||
| 38 | =head1 METHODS | ||||||||||||
| 39 | |||||||||||||
| 40 | L<Mango::BSON::Time> inherits all methods from L<Mojo::Base> 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<Mango::BSON::Time> 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<RFC 3339|http://tools.ietf.org/html/rfc3339> 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<Mango::BSON::Time> 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</to_string>. | ||||||||||||
| 89 | |||||||||||||
| 90 | =head1 SEE ALSO | ||||||||||||
| 91 | |||||||||||||
| 92 | L<Mango>, L<Mojolicious::Guides>, L<http://mojolicio.us>. | ||||||||||||
| 93 | |||||||||||||
| 94 | =cut | ||||||||||||