line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Duration::es; |
2
|
3
|
|
|
3
|
|
53079
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
95
|
|
3
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
157
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
17
|
use base qw(Exporter); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
412
|
|
8
|
|
|
|
|
|
|
our @EXPORT = qw( later later_exact earlier earlier_exact |
9
|
|
|
|
|
|
|
ago ago_exact from_now from_now_exact |
10
|
|
|
|
|
|
|
duration duration_exact concise ); |
11
|
|
|
|
|
|
|
our @EXPORT_OK = ('interval', @EXPORT); |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
1866
|
use Time::Duration qw(); |
|
3
|
|
|
|
|
7235
|
|
|
3
|
|
|
|
|
3508
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $MILLISECOND = 0; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub concise ($) { |
18
|
29
|
|
|
29
|
0
|
72
|
my $string = $_[0]; |
19
|
29
|
|
|
|
|
44
|
$string =~ tr/,//d; |
20
|
29
|
|
|
|
|
73
|
$string =~ s/\by\b//; |
21
|
29
|
|
|
|
|
177
|
$string =~ s/\b(año|día|hora|minuto|segundo)s?\b/substr($1,0,1)/eg; |
|
44
|
|
|
|
|
195
|
|
22
|
29
|
|
|
|
|
30
|
$string =~ s/\b(milisegundo)s?\b/ms/g; |
23
|
29
|
|
|
|
|
134
|
$string =~ s/\s*(\d+)\s*/$1/g; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# dirty hack to restore prefixed intervals |
26
|
29
|
|
|
|
|
38
|
$string =~ s/en([0-9])/en $1/; # en matches momento |
27
|
29
|
|
|
|
|
50
|
$string =~ s/hace/hace /; |
28
|
|
|
|
|
|
|
|
29
|
29
|
|
|
|
|
112
|
return $string; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub later { # ' earlier', ' later', 'right then' |
33
|
68
|
|
|
68
|
0
|
166
|
interval( $_[0], $_[1], '%s antes', '%s después', 'al momento'); } |
34
|
|
|
|
|
|
|
sub later_exact { # ' earlier', ' later', 'right then' |
35
|
31
|
|
|
31
|
0
|
89
|
interval_exact($_[0], $_[1], '%s antes', '%s después', 'al momento'); } |
36
|
|
|
|
|
|
|
sub earlier { # ' later', ' earlier', 'right then' |
37
|
6
|
|
|
6
|
0
|
21
|
interval( $_[0], $_[1], '%s después', '%s antes', 'al momento'); } |
38
|
|
|
|
|
|
|
sub earlier_exact { # ' later', ' earlier', 'right then' |
39
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s después', '%s antes', 'al momento'); } |
40
|
|
|
|
|
|
|
sub ago { # ' from now', ' ago', 'right now' |
41
|
11
|
|
|
11
|
0
|
35
|
interval( $_[0], $_[1], 'en %s', 'hace %s', 'ahora'); } |
42
|
|
|
|
|
|
|
sub ago_exact { # ' from now', ' ago', 'right now' |
43
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], 'en %s', 'hace %s', 'ahora'); } |
44
|
|
|
|
|
|
|
sub from_now { # ' ago', ' from now', 'right now' |
45
|
6
|
|
|
6
|
0
|
20
|
interval( $_[0], $_[1], 'hace %s', 'en %s', 'ahora'); } |
46
|
|
|
|
|
|
|
sub from_now_exact { # ' ago', ' from now', 'right now' |
47
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], 'hace %s', 'en %s', 'ahora'); } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub duration_exact { |
50
|
2
|
|
|
2
|
0
|
4
|
my $span = $_[0]; # interval in seconds |
51
|
2
|
|
50
|
|
|
13
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
52
|
2
|
50
|
|
|
|
4
|
return '0 segundos' unless $span; |
53
|
2
|
|
|
|
|
4
|
_render('%s', |
54
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub duration { |
58
|
16
|
|
|
16
|
0
|
36
|
my $span = $_[0]; # interval in seconds |
59
|
16
|
|
100
|
|
|
84
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
60
|
16
|
100
|
|
|
|
38
|
return '0 segundos' unless $span; |
61
|
14
|
|
|
|
|
38
|
_render('%s', |
62
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
63
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub interval_exact { |
67
|
31
|
|
|
31
|
0
|
27
|
my $span = $_[0]; # interval, in seconds |
68
|
|
|
|
|
|
|
# precision is ignored |
69
|
31
|
100
|
|
|
|
65
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
50
|
|
|
|
|
|
70
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
71
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
72
|
30
|
|
|
|
|
52
|
_render($direction, |
73
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub interval { |
77
|
91
|
|
|
91
|
0
|
111
|
my $span = $_[0]; # interval, in seconds |
78
|
91
|
|
100
|
|
|
387
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
79
|
91
|
100
|
|
|
|
188
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
100
|
|
|
|
|
|
80
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
81
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
82
|
81
|
|
|
|
|
154
|
_render($direction, |
83
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
84
|
|
|
|
|
|
|
Time::Duration::_separate($span))); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
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
|
|
|
127
|
|
4045
|
my $direction = shift @_; |
98
|
|
|
|
|
|
|
my @wheel = map |
99
|
|
|
|
|
|
|
{ |
100
|
127
|
|
|
|
|
155
|
( $_->[1] == 0) ? () # zero wheels |
101
|
635
|
100
|
|
|
|
1323
|
: $_->[1] . ' ' . $en2es{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] |
|
|
100
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
@_; |
105
|
|
|
|
|
|
|
|
106
|
127
|
50
|
|
|
|
241
|
return 'ahora' unless @wheel; # sanity |
107
|
127
|
|
|
|
|
109
|
my $result; |
108
|
127
|
100
|
|
|
|
177
|
if(@wheel == 1) { |
|
|
100
|
|
|
|
|
|
109
|
51
|
|
|
|
|
46
|
$result = $wheel[0]; |
110
|
|
|
|
|
|
|
} elsif(@wheel == 2) { |
111
|
37
|
|
|
|
|
47
|
$result = "$wheel[0] y $wheel[1]"; |
112
|
|
|
|
|
|
|
} else { |
113
|
39
|
|
|
|
|
47
|
$wheel[-1] = "y $wheel[-1]"; |
114
|
39
|
|
|
|
|
71
|
$result = join q{, }, @wheel; |
115
|
|
|
|
|
|
|
} |
116
|
127
|
|
|
|
|
781
|
return sprintf($direction, $result); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |