line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Duration::es; |
2
|
3
|
|
|
3
|
|
40317
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
74
|
|
3
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
112
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
10
|
use base qw(Exporter); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
326
|
|
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
|
|
1603
|
use Time::Duration qw(); |
|
3
|
|
|
|
|
4039
|
|
|
3
|
|
|
|
|
1893
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $MILLISECOND = 0; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub concise ($) { |
18
|
29
|
|
|
29
|
0
|
28
|
my $string = $_[0]; |
19
|
29
|
|
|
|
|
41
|
$string =~ tr/,//d; |
20
|
29
|
|
|
|
|
66
|
$string =~ s/\by\b//; |
21
|
29
|
|
|
|
|
123
|
$string =~ s/\b(año|día|hora|minuto|segundo)s?\b/substr($1,0,1)/eg; |
|
44
|
|
|
|
|
137
|
|
22
|
29
|
|
|
|
|
32
|
$string =~ s/\b(milisegundo)s?\b/ms/g; |
23
|
29
|
|
|
|
|
123
|
$string =~ s/\s*(\d+)\s*/$1/g; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# dirty hack to restore prefixed intervals |
26
|
29
|
|
|
|
|
33
|
$string =~ s/en([0-9])/en $1/; # en matches momento |
27
|
29
|
|
|
|
|
29
|
$string =~ s/hace/hace /; |
28
|
|
|
|
|
|
|
|
29
|
29
|
|
|
|
|
97
|
return $string; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub later { # ' earlier', ' later', 'right then' |
33
|
68
|
|
|
68
|
0
|
170
|
interval( $_[0], $_[1], '%s antes', '%s después', 'al momento'); } |
34
|
|
|
|
|
|
|
sub later_exact { # ' earlier', ' later', 'right then' |
35
|
31
|
|
|
31
|
0
|
88
|
interval_exact($_[0], $_[1], '%s antes', '%s después', 'al momento'); } |
36
|
|
|
|
|
|
|
sub earlier { # ' later', ' earlier', 'right then' |
37
|
6
|
|
|
6
|
0
|
20
|
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
|
34
|
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
|
19
|
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
|
3
|
my $span = $_[0]; # interval in seconds |
51
|
2
|
|
50
|
|
|
15
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
52
|
2
|
50
|
|
|
|
4
|
return '0 segundos' unless $span; |
53
|
2
|
|
|
|
|
5
|
_render('%s', |
54
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub duration { |
58
|
16
|
|
|
16
|
0
|
33
|
my $span = $_[0]; # interval in seconds |
59
|
16
|
|
100
|
|
|
82
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
60
|
16
|
100
|
|
|
|
38
|
return '0 segundos' unless $span; |
61
|
14
|
|
|
|
|
36
|
_render('%s', |
62
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
63
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub interval_exact { |
67
|
31
|
|
|
31
|
0
|
28
|
my $span = $_[0]; # interval, in seconds |
68
|
|
|
|
|
|
|
# precision is ignored |
69
|
31
|
100
|
|
|
|
64
|
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
|
|
|
|
|
59
|
_render($direction, |
73
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub interval { |
77
|
91
|
|
|
91
|
0
|
91
|
my $span = $_[0]; # interval, in seconds |
78
|
91
|
|
100
|
|
|
412
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
79
|
91
|
100
|
|
|
|
187
|
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
|
|
|
|
|
144
|
_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
|
|
3834
|
my $direction = shift @_; |
98
|
|
|
|
|
|
|
my @wheel = map |
99
|
|
|
|
|
|
|
{ |
100
|
127
|
|
|
|
|
149
|
( $_->[1] == 0) ? () # zero wheels |
101
|
635
|
100
|
|
|
|
1233
|
: $_->[1] . ' ' . $en2es{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] |
|
|
100
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
@_; |
105
|
|
|
|
|
|
|
|
106
|
127
|
50
|
|
|
|
211
|
return 'ahora' unless @wheel; # sanity |
107
|
127
|
|
|
|
|
87
|
my $result; |
108
|
127
|
100
|
|
|
|
187
|
if(@wheel == 1) { |
|
|
100
|
|
|
|
|
|
109
|
51
|
|
|
|
|
41
|
$result = $wheel[0]; |
110
|
|
|
|
|
|
|
} elsif(@wheel == 2) { |
111
|
37
|
|
|
|
|
51
|
$result = "$wheel[0] y $wheel[1]"; |
112
|
|
|
|
|
|
|
} else { |
113
|
39
|
|
|
|
|
49
|
$wheel[-1] = "y $wheel[-1]"; |
114
|
39
|
|
|
|
|
65
|
$result = join q{, }, @wheel; |
115
|
|
|
|
|
|
|
} |
116
|
127
|
|
|
|
|
717
|
return sprintf($direction, $result); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |