| 1 | package Finance::CoinbasePro::API::CLI::Util::DateUtil; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our @EXPORT_OK = qw( getdatetime convert_seconds_to_human_time my_str2time ); | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Time::Moment; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # returns 19 character string like "2004-04-04 12:30:59" | ||||||||||||||||||||||||||||
| 9 | sub getdatetime { | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | my $t = shift || time(); | ||||||||||||||||||||||||||
|
Subroutine
getdatetime: called CC=2 SCAR=8.1
Pod
documented
Condition33%1/3
shift() || time
MC/DC0%0/2
shift() || time
shift()
time
Truth table33%1/3
A || B
A= shift()B= time
| |||||||||||||||||||||||||||||
| 11 | 1 | return POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime( $t ) ); | |||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # converts seconds to human-readable. | ||||||||||||||||||||||||||||
| 15 | sub convert_seconds_to_human_time { | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | my $t = shift; | ||||||||||||||||||||||||||
|
Subroutine
convert_seconds_to_human_time: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $precision = shift // 2; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() // 2
MC/DC0%0/1
shift() // 2
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | my @table = ( | |||||||||||||||||||||||||||
| 20 | [86400*365.25, " years"], | ||||||||||||||||||||||||||||
| 21 | [86400, " days"], | ||||||||||||||||||||||||||||
| 22 | [3600, " hrs"], | ||||||||||||||||||||||||||||
| 23 | [60, " mins"], | ||||||||||||||||||||||||||||
| 24 | [1, " secs"], | ||||||||||||||||||||||||||||
| 25 | [0.001, " ms"], | ||||||||||||||||||||||||||||
| 26 | [0.000001, " us"], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | 0 | return _convert_units_to_human_size( $t, \@table, $precision ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub _convert_units_to_human_size { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my ($units, $tableref, $precision) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_convert_units_to_human_size: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $precision = 2 unless defined($precision); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | #print "---$bytes---"; | ||||||||||||||||||||||||||||
| 35 | 0 | for my $row (@$tableref) { | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | if (abs($units) >= $row->[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | if (0) { # one way | |||||||||||||||||||||||||||
| 38 | my $value = int($units / $row->[0]); | ||||||||||||||||||||||||||||
| 39 | $value = sprintf( "%.${precision}f", $units / $row->[0]) if (length($value) < 3); | ||||||||||||||||||||||||||||
| 40 | return $value . $row->[1]; | ||||||||||||||||||||||||||||
| 41 | } else { # another way | ||||||||||||||||||||||||||||
| 42 | 0 | my $value = $units / $row->[0]; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($value =~ /^\d+(\.0*)?$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $value = int( $value ); | |||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | 0 | $value = sprintf( "%.${precision}f", $value); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (length($value) > 6 && $value =~ /\d\.\d\d$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $value > 6 and $value =~ /\d\.\d\d$/
MC/DC0%0/2
length $value > 6 and $value =~ /\d\.\d\d$/
length $value > 6
$value =~ /\d\.\d\d$/
Truth table0%0/3
A and B
A= length $value > 6B= $value =~ /\d\.\d\d$/
| |||||||||||||||||||||||||||||
| 49 | 0 | chop $value; # remove last of the digits | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | return $value . $row->[1]; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | return int($units); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # like str2time, but uses Time::Piece to parse more date formats | ||||||||||||||||||||||||||||
| 60 | sub my_str2time { | ||||||||||||||||||||||||||||
| 61 | 1 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
my_str2time: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 1 | my $tm = Time::Moment->from_string($s); | |||||||||||||||||||||||||||
| 63 | 1 | my $t = $tm->epoch(); | |||||||||||||||||||||||||||
| 64 | 1 | return $t; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #################### pod generated by Pod::Autopod - keep this line to make pod updates possible #################### | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =head1 NAME | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | Finance::CoinbasePro::API::CLI::Util::DateUtil | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | returns 19 character string like "2004-04-04 12:30:59" | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =head1 REQUIRES | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | L<Time::Moment> | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =head1 IMPLEMENTS | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | L<Exporter> | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 METHODS | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head2 convert_seconds_to_human_time | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | $self->convert_seconds_to_human_time(); | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | converts seconds to human-readable. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head2 getdatetime | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | $self->getdatetime(); | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | returns 19 character string like "2004-04-04 12:30:59" | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =head2 my_str2time | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | $self->my_str2time(); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | like str2time, but uses Time::Piece to parse more date formats | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||