| 1 | package Time::Duration::es; | ||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||
| 4 | |||||||||||||||||
| 5 | 3 | our $VERSION = '0.01'; | |||||||||||||||
| 6 | |||||||||||||||||
| 7 | 3 | ▶ | use base qw(Exporter); | ||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||
| 8 | 3 | our @EXPORT = qw( later later_exact earlier earlier_exact | |||||||||||||||
| 9 | ago ago_exact from_now from_now_exact | ||||||||||||||||
| 10 | duration duration_exact concise ); | ||||||||||||||||
| 11 | 3 | our @EXPORT_OK = ('interval', @EXPORT); | |||||||||||||||
| 12 | |||||||||||||||||
| 13 | 3 | ▶ | use Time::Duration qw(); | ||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||
| 14 | |||||||||||||||||
| 15 | 3 | our $MILLISECOND = 0; | |||||||||||||||
| 16 | |||||||||||||||||
| 17 | sub concise ($) { | ||||||||||||||||
| 18 | 29 | ▶ | my $string = $_[0]; | ||||||||||||||
|
Subroutine
concise: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 19 | 29 | $string =~ tr/,//d; | |||||||||||||||
| 20 | 29 | $string =~ s/\by\b//; | |||||||||||||||
| 21 | 29 | $string =~ s/\b(año|día|hora|minuto|segundo)s?\b/substr($1,0,1)/eg; | |||||||||||||||
| 22 | 29 | $string =~ s/\b(milisegundo)s?\b/ms/g; | |||||||||||||||
| 23 | 29 | $string =~ s/\s*(\d+)\s*/$1/g; | |||||||||||||||
| 24 | |||||||||||||||||
| 25 | # dirty hack to restore prefixed intervals | ||||||||||||||||
| 26 | 29 | $string =~ s/en([0-9])/en $1/; # en matches momento | |||||||||||||||
| 27 | 29 | $string =~ s/hace/hace /; | |||||||||||||||
| 28 | |||||||||||||||||
| 29 | 29 | return $string; | |||||||||||||||
| 30 | } | ||||||||||||||||
| 31 | |||||||||||||||||
| 32 | sub later { # ' earlier', ' later', 'right then' | ||||||||||||||||
| 33 | 68 | ▶ | interval( $_[0], $_[1], '%s antes', '%s después', 'al momento'); } | ||||||||||||||
|
Subroutine
later: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 34 | sub later_exact { # ' earlier', ' later', 'right then' | ||||||||||||||||
| 35 | 31 | ▶ | interval_exact($_[0], $_[1], '%s antes', '%s después', 'al momento'); } | ||||||||||||||
|
Subroutine
later_exact: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 36 | sub earlier { # ' later', ' earlier', 'right then' | ||||||||||||||||
| 37 | 6 | ▶ | interval( $_[0], $_[1], '%s después', '%s antes', 'al momento'); } | ||||||||||||||
|
Subroutine
earlier: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 38 | sub earlier_exact { # ' later', ' earlier', 'right then' | ||||||||||||||||
| 39 | 0 | ▶ | interval_exact($_[0], $_[1], '%s después', '%s antes', 'al momento'); } | ||||||||||||||
|
Subroutine
earlier_exact: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||
| 40 | sub ago { # ' from now', ' ago', 'right now' | ||||||||||||||||
| 41 | 11 | ▶ | interval( $_[0], $_[1], 'en %s', 'hace %s', 'ahora'); } | ||||||||||||||
|
Subroutine
ago: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 42 | sub ago_exact { # ' from now', ' ago', 'right now' | ||||||||||||||||
| 43 | 0 | ▶ | interval_exact($_[0], $_[1], 'en %s', 'hace %s', 'ahora'); } | ||||||||||||||
|
Subroutine
ago_exact: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||
| 44 | sub from_now { # ' ago', ' from now', 'right now' | ||||||||||||||||
| 45 | 6 | ▶ | interval( $_[0], $_[1], 'hace %s', 'en %s', 'ahora'); } | ||||||||||||||
|
Subroutine
from_now: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||
| 46 | sub from_now_exact { # ' ago', ' from now', 'right now' | ||||||||||||||||
| 47 | 0 | ▶ | interval_exact($_[0], $_[1], 'hace %s', 'en %s', 'ahora'); } | ||||||||||||||
|
Subroutine
from_now_exact: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||
| 48 | |||||||||||||||||
| 49 | sub duration_exact { | ||||||||||||||||
| 50 | 2 | ▶ | my $span = $_[0]; # interval in seconds | ||||||||||||||
|
Subroutine
duration_exact: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||
| 51 | 2 | ▶ | my $precision = int($_[1] || 0) || 2; # precision (default: 2) | ||||||||||||||
|
Condition50%2/4
int($_[1] || 0) || 2
$_[1] || 0
MC/DC0%0/1
int($_[1] || 0) || 2
$_[1]
Truth table50%1/2
A
A= $_[1]
| |||||||||||||||||
| 52 | 2 | ▶ | return '0 segundos' unless $span; | ||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||
| 53 | 2 | _render('%s', | |||||||||||||||
| 54 | Time::Duration::_separate(abs $span)); | ||||||||||||||||
| 55 | } | ||||||||||||||||
| 56 | |||||||||||||||||
| 57 | sub duration { | ||||||||||||||||
| 58 | 16 | ▶ | my $span = $_[0]; # interval in seconds | ||||||||||||||
|
Subroutine
duration: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||
| 59 | 16 | ▶ | my $precision = int($_[1] || 0) || 2; # precision (default: 2) | ||||||||||||||
|
Condition100%4/4
int($_[1] || 0) || 2
$_[1] || 0
MC/DC100%1/1
int($_[1] || 0) || 2
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||
| 60 | 16 | ▶ | return '0 segundos' unless $span; | ||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||
| 61 | 14 | _render('%s', | |||||||||||||||
| 62 | Time::Duration::_approximate($precision, | ||||||||||||||||
| 63 | Time::Duration::_separate(abs $span))); | ||||||||||||||||
| 64 | } | ||||||||||||||||
| 65 | |||||||||||||||||
| 66 | sub interval_exact { | ||||||||||||||||
| 67 | 31 | ▶ | my $span = $_[0]; # interval, in seconds | ||||||||||||||
|
Subroutine
interval_exact: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||
| 68 | # precision is ignored | ||||||||||||||||
| 69 | 31 | ▶ | my $direction = ($span <= -1) ? $_[2] # what a neg number gets | ||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||
| 70 | : ($span >= 1) ? $_[3] # what a pos number gets | ||||||||||||||||
| 71 | : return $_[4]; # what zero gets | ||||||||||||||||
| 72 | 30 | _render($direction, | |||||||||||||||
| 73 | Time::Duration::_separate($span)); | ||||||||||||||||
| 74 | } | ||||||||||||||||
| 75 | |||||||||||||||||
| 76 | sub interval { | ||||||||||||||||
| 77 | 91 | ▶ | my $span = $_[0]; # interval, in seconds | ||||||||||||||
|
Subroutine
interval: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||
| 78 | 91 | ▶ | my $precision = int($_[1] || 0) || 2; # precision (default: 2) | ||||||||||||||
|
Condition100%4/4
int($_[1] || 0) || 2
$_[1] || 0
MC/DC100%1/1
int($_[1] || 0) || 2
$_[1]
Truth table100%2/2
A
A= $_[1]
| |||||||||||||||||
| 79 | 91 | ▶ | my $direction = ($span <= -1) ? $_[2] # what a neg number gets | ||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||
| 80 | : ($span >= 1) ? $_[3] # what a pos number gets | ||||||||||||||||
| 81 | : return $_[4]; # what zero gets | ||||||||||||||||
| 82 | 81 | _render($direction, | |||||||||||||||
| 83 | Time::Duration::_approximate($precision, | ||||||||||||||||
| 84 | Time::Duration::_separate($span))); | ||||||||||||||||
| 85 | } | ||||||||||||||||
| 86 | |||||||||||||||||
| 87 | 3 | my %en2es = ( | |||||||||||||||
| 88 | second => ['segundo', 'segundos'], | ||||||||||||||||
| 89 | minute => ['minuto' , 'minutos' ], | ||||||||||||||||
| 90 | hour => ['hora' , 'horas' ], | ||||||||||||||||
| 91 | day => ['día' , 'días' ], | ||||||||||||||||
| 92 | year => ['año' , 'años' ], | ||||||||||||||||
| 93 | ); | ||||||||||||||||
| 94 | |||||||||||||||||
| 95 | sub _render { | ||||||||||||||||
| 96 | # Make it into Spanish | ||||||||||||||||
| 97 | 127 | ▶ | my $direction = shift @_; | ||||||||||||||
|
Subroutine
_render: called CC=6 SCAR=17.9
| |||||||||||||||||
| 98 | my @wheel = map | ||||||||||||||||
| 99 | { | ||||||||||||||||
| 100 | 127 | ( $_->[1] == 0) ? () # zero wheels | |||||||||||||||
| 101 | 635 | ▶ | : $_->[1] . ' ' . $en2es{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] | ||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||
| 102 | } | ||||||||||||||||
| 103 | |||||||||||||||||
| 104 | @_; | ||||||||||||||||
| 105 | |||||||||||||||||
| 106 | 127 | ▶ | return 'ahora' unless @wheel; # sanity | ||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||
| 107 | 127 | my $result; | |||||||||||||||
| 108 | 127 | ▶ | if(@wheel == 1) { | ||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||
| 109 | 51 | $result = $wheel[0]; | |||||||||||||||
| 110 | } elsif(@wheel == 2) { | ||||||||||||||||
| 111 | 37 | $result = "$wheel[0] y $wheel[1]"; | |||||||||||||||
| 112 | } else { | ||||||||||||||||
| 113 | 39 | $wheel[-1] = "y $wheel[-1]"; | |||||||||||||||
| 114 | 39 | $result = join q{, }, @wheel; | |||||||||||||||
| 115 | } | ||||||||||||||||
| 116 | 127 | return sprintf($direction, $result); | |||||||||||||||
| 117 | } | ||||||||||||||||
| 118 | |||||||||||||||||
| 119 | 3 | 1; | |||||||||||||||
| 120 | __END__ | ||||||||||||||||