| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use Time::HiRes (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use POSIX (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use NG::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | NG::Class::def 'NG::Time' => [] => { | ||||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | now => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 9 | 0 | my @t = localtime; | |||||||||
| 10 | 0 | NG::Time->new( | |||||||||
| 11 | year => $t[5] + 1900, | ||||||||||
| 12 | month => $t[4] + 1, | ||||||||||
| 13 | day => $t[3], | ||||||||||
| 14 | hour => $t[2], | ||||||||||
| 15 | minute => $t[1], | ||||||||||
| 16 | second => $t[0], | ||||||||||
| 17 | ); | ||||||||||
| 18 | }, | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | year => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 21 | 0 | ▶ | defined $_[0]->{year} ? $_[0]->{year} : 1970; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | }, | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | month => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 25 | 0 | ▶ | $_[0]->{month} || 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | }, | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | day => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 29 | 0 | ▶ | $_[0]->{day} || 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | }, | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | hour => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 33 | 0 | ▶ | $_[0]->{hour} || 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | }, | ||||||||||
| 35 | |||||||||||
| 36 | 0 | ▶ | minute => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 37 | 0 | ▶ | $_[0]->{minute} || 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | }, | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | second => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 41 | 0 | ▶ | $_[0]->{second} || 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | }, | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | microsecond => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 45 | 0 | ▶ | $_[0]->{second} || +(Time::HiRes::gettimeofday)[1]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | }, | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | strftime => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 49 | 0 | my $self = shift; | |||||||||
| 50 | 0 | my $format = shift; | |||||||||
| 51 | 0 | my @need_t; | |||||||||
| 52 | 0 | ▶ | if ( ref( $_[0] ) eq 'NG::Time' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 0 | @need_t = localtime( shift->to_epoch ); | |||||||||
| 54 | } | ||||||||||
| 55 | else { | ||||||||||
| 56 | 0 | @need_t = @_; | |||||||||
| 57 | } | ||||||||||
| 58 | 0 | POSIX::strftime( $format, @need_t ); | |||||||||
| 59 | }, | ||||||||||
| 60 | |||||||||||
| 61 | 0 | ▶ | to_epoch => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 62 | 0 | my $self = shift; | |||||||||
| 63 | 0 | POSIX::mktime( | |||||||||
| 64 | $self->second, $self->minute, $self->hour, $self->day, | ||||||||||
| 65 | $self->month - 1, | ||||||||||
| 66 | $self->year - 1900 | ||||||||||
| 67 | ); | ||||||||||
| 68 | }, | ||||||||||
| 69 | |||||||||||
| 70 | 0 | ▶ | from_epoch => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 71 | 0 | my $self = shift; | |||||||||
| 72 | 0 | my @t = localtime(shift); | |||||||||
| 73 | 0 | $self->new( | |||||||||
| 74 | year => $t[5] + 1900, | ||||||||||
| 75 | month => $t[4] + 1, | ||||||||||
| 76 | day => $t[3], | ||||||||||
| 77 | hour => $t[2], | ||||||||||
| 78 | minute => $t[1], | ||||||||||
| 79 | second => $t[0], | ||||||||||
| 80 | ); | ||||||||||
| 81 | }, | ||||||||||
| 82 | |||||||||||
| 83 | 0 | ▶ | to_float => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 84 | 0 | return Time::HiRes::time; | |||||||||
| 85 | }, | ||||||||||
| 86 | |||||||||||
| 87 | 1 | }; | |||||||||
| 88 | |||||||||||
| 89 | 1 | 1; | |||||||||