line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Duration::pt; |
2
|
3
|
|
|
3
|
|
72614
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
103
|
|
3
|
3
|
|
|
3
|
|
50
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
133
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
19
|
use base qw(Exporter); |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
505
|
|
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
|
|
18
|
use constant DEBUG => 0; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
282
|
|
14
|
3
|
|
|
3
|
|
3212
|
use Time::Duration qw(); |
|
3
|
|
|
|
|
6876
|
|
|
3
|
|
|
|
|
2843
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub concise ($) { |
17
|
29
|
|
|
29
|
0
|
46
|
my $string = $_[0]; |
18
|
|
|
|
|
|
|
# print "in : $string\n"; |
19
|
29
|
|
|
|
|
60
|
$string =~ tr/,//d; |
20
|
29
|
|
|
|
|
141
|
$string =~ s/\be\b//; |
21
|
29
|
|
|
|
|
168
|
$string =~ s/\b(ano|dia|hora|minuto|segundo)s?\b/substr($1,0,1)/eg; |
|
44
|
|
|
|
|
298
|
|
22
|
29
|
|
|
|
|
341
|
$string =~ s/\s*(\d+)\s*/$1/g; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# dirty hack to restore prefixed intervals |
25
|
29
|
|
|
|
|
56
|
$string =~ s/daqui a/daqui a /; |
26
|
|
|
|
|
|
|
|
27
|
29
|
|
|
|
|
148
|
return $string; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub later { |
31
|
68
|
|
|
68
|
0
|
248
|
interval( $_[0], $_[1], '%s antes', '%s depois', 'agora'); } |
32
|
|
|
|
|
|
|
sub later_exact { |
33
|
31
|
|
|
31
|
0
|
136
|
interval_exact($_[0], $_[1], '%s antes', '%s depois', 'agora'); } |
34
|
|
|
|
|
|
|
sub earlier { |
35
|
6
|
|
|
6
|
0
|
25
|
interval( $_[0], $_[1], '%s depois', '%s antes', 'agora'); } |
36
|
|
|
|
|
|
|
sub earlier_exact { |
37
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s depois', '%s antes', 'agora'); } |
38
|
|
|
|
|
|
|
sub ago { |
39
|
11
|
|
|
11
|
0
|
45
|
interval( $_[0], $_[1], 'daqui a %s', '%s atrás', 'agora'); } |
40
|
|
|
|
|
|
|
sub ago_exact { |
41
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], 'daqui a %s', '%s atrás', 'agora'); } |
42
|
|
|
|
|
|
|
sub from_now { |
43
|
6
|
|
|
6
|
0
|
27
|
interval( $_[0], $_[1], '%s atrás', 'daqui a %s', 'agora'); } |
44
|
|
|
|
|
|
|
sub from_now_exact { |
45
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s atrás', 'daqui a %s', 'agora'); } |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub duration_exact { |
50
|
2
|
|
|
2
|
0
|
7
|
my $span = $_[0]; # interval in seconds |
51
|
2
|
|
50
|
|
|
21
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
52
|
2
|
50
|
|
|
|
8
|
return '0 segundos' unless $span; |
53
|
2
|
|
|
|
|
8
|
_render('%s', |
54
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub duration { |
58
|
16
|
|
|
16
|
0
|
47
|
my $span = $_[0]; # interval in seconds |
59
|
16
|
|
100
|
|
|
112
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
60
|
16
|
100
|
|
|
|
54
|
return '0 segundos' unless $span; |
61
|
14
|
|
|
|
|
54
|
_render('%s', |
62
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
63
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub interval_exact { |
67
|
31
|
|
|
31
|
0
|
46
|
my $span = $_[0]; # interval, in seconds |
68
|
|
|
|
|
|
|
# precision is ignored |
69
|
31
|
100
|
|
|
|
95
|
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
|
|
|
|
|
82
|
_render($direction, |
73
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub interval { |
77
|
91
|
|
|
91
|
0
|
290
|
my $span = $_[0]; # interval, in seconds |
78
|
91
|
|
100
|
|
|
572
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
79
|
91
|
100
|
|
|
|
352
|
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
|
|
|
|
|
221
|
_render($direction, |
83
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
84
|
|
|
|
|
|
|
Time::Duration::_separate($span))); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my %en2pt = ( |
88
|
|
|
|
|
|
|
second => ['segundo', 'segundos'], |
89
|
|
|
|
|
|
|
minute => ['minuto' , 'minutos' ], |
90
|
|
|
|
|
|
|
hour => ['hora' , 'horas' ], |
91
|
|
|
|
|
|
|
day => ['dia' , 'dias' ], |
92
|
|
|
|
|
|
|
year => ['ano' , 'anos' ], |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _render { |
96
|
|
|
|
|
|
|
# Make it into Portuguese |
97
|
127
|
|
|
127
|
|
5993
|
my $direction = shift @_; |
98
|
635
|
100
|
|
|
|
2256
|
my @wheel = map |
|
|
100
|
|
|
|
|
|
99
|
|
|
|
|
|
|
{ |
100
|
127
|
|
|
|
|
1614
|
( $_->[1] == 0) ? () # zero wheels |
101
|
|
|
|
|
|
|
: $_->[1] . ' ' . $en2pt{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
@_; |
105
|
|
|
|
|
|
|
|
106
|
127
|
50
|
|
|
|
289
|
return 'agora' unless @wheel; # sanity |
107
|
127
|
|
|
|
|
128
|
my $result; |
108
|
127
|
100
|
|
|
|
256
|
if(@wheel == 1) { |
|
|
100
|
|
|
|
|
|
109
|
51
|
|
|
|
|
79
|
$result = $wheel[0]; |
110
|
|
|
|
|
|
|
} elsif(@wheel == 2) { |
111
|
37
|
|
|
|
|
75
|
$result = "$wheel[0] e $wheel[1]"; |
112
|
|
|
|
|
|
|
} else { |
113
|
39
|
|
|
|
|
82
|
$wheel[-1] = "e $wheel[-1]"; |
114
|
39
|
|
|
|
|
90
|
$result = join q{, }, @wheel; |
115
|
|
|
|
|
|
|
} |
116
|
127
|
|
|
|
|
1500
|
return sprintf($direction, $result); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
1; |
120
|
|
|
|
|
|
|
__END__ |