line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Duration::fr; |
2
|
3
|
|
|
3
|
|
66663
|
use encoding 'utf-8'; |
|
3
|
|
|
|
|
38244
|
|
|
3
|
|
|
|
|
19
|
|
3
|
3
|
|
|
3
|
|
1761
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
81
|
|
4
|
3
|
|
|
3
|
|
29
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
142
|
use base qw< Exporter >; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
96
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw< |
11
|
|
|
|
|
|
|
later later_exact earlier earlier_exact |
12
|
|
|
|
|
|
|
ago ago_exact from_now from_now_exact |
13
|
|
|
|
|
|
|
duration duration_exact concise |
14
|
|
|
|
|
|
|
>; |
15
|
|
|
|
|
|
|
our @EXPORT_OK = ( "interval", @EXPORT ); |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
611
|
use constant DEBUG => 0; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
143
|
|
18
|
3
|
|
|
3
|
|
2913
|
use Time::Duration (); |
|
3
|
|
|
|
|
5502
|
|
|
3
|
|
|
|
|
54
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %en2fr = ( |
22
|
|
|
|
|
|
|
second => ["seconde", "secondes"], |
23
|
|
|
|
|
|
|
minute => ["minute" , "minutes" ], |
24
|
|
|
|
|
|
|
hour => ["heure" , "heures" ], |
25
|
|
|
|
|
|
|
day => ["jour" , "jours" ], |
26
|
|
|
|
|
|
|
year => ["année" , "années" ], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my %short = map { $_=> substr($_, 0, 1) } map { @$_ } values %en2fr; |
30
|
|
|
|
|
|
|
my $comp_re = join "|", map { $_->[0] } values %en2fr; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub concise ($) { |
34
|
29
|
|
|
29
|
1
|
36
|
my $string = $_[0]; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#print "in : $string\n"; |
37
|
3
|
|
|
3
|
|
4198
|
$string =~ tr/,//d; |
|
3
|
|
|
|
|
33
|
|
|
3
|
|
|
|
|
43
|
|
|
29
|
|
|
|
|
95
|
|
38
|
29
|
|
|
|
|
85
|
$string =~ s/\bet\b//; |
39
|
29
|
|
|
|
|
376
|
$string =~ s/\b($comp_re)s?\b/$short{$1}/g; |
40
|
29
|
|
|
|
|
230
|
$string =~ s/\s*(\d+)\s*/$1/g; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# restore prefixed intervals |
43
|
29
|
|
|
|
|
53
|
$string =~ s/dans/dans /; |
44
|
29
|
|
|
|
|
77
|
$string =~ s/il y a/il y a /; |
45
|
|
|
|
|
|
|
|
46
|
29
|
|
|
|
|
167
|
return $string; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub later { |
50
|
68
|
|
|
68
|
1
|
376
|
interval( $_[0], $_[1], "%s plus tôt", "%s plus tard", "maintenant"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub later_exact { |
54
|
31
|
|
|
31
|
1
|
85
|
interval_exact($_[0], $_[1], "%s plus tôt", "%s plus tard", "maintenant"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub earlier { |
58
|
6
|
|
|
6
|
1
|
17
|
interval( $_[0], $_[1], "%s plus tard", "%s plus tôt", "maintenant"); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub earlier_exact { |
62
|
0
|
|
|
0
|
1
|
0
|
interval_exact($_[0], $_[1], "%s plus tard", "%s plus tôt", "maintenant"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub ago { |
66
|
6
|
|
|
6
|
1
|
19
|
interval( $_[0], $_[1], 'dans %s', 'il y a %s', "maintenant"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub ago_exact { |
70
|
0
|
|
|
0
|
1
|
0
|
interval_exact($_[0], $_[1], 'dans %s', 'il y a %s', "maintenant"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub from_now { |
74
|
6
|
|
|
6
|
1
|
16
|
interval( $_[0], $_[1], 'il y a %s', 'dans %s', "maintenant"); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub from_now_exact { |
78
|
0
|
|
|
0
|
1
|
0
|
interval_exact($_[0], $_[1], 'il y a %s', 'dans %s', "maintenant"); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub duration_exact { |
83
|
2
|
|
|
2
|
1
|
31
|
my $span = $_[0]; # interval in seconds |
84
|
2
|
|
50
|
|
|
18
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
85
|
2
|
50
|
|
|
|
6
|
return '0 seconde' unless $span; |
86
|
2
|
|
|
|
|
13
|
_render('%s', |
87
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub duration { |
91
|
14
|
|
|
14
|
1
|
44
|
my $span = $_[0]; # interval in seconds |
92
|
14
|
|
100
|
|
|
77
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
93
|
14
|
100
|
|
|
|
35
|
return '0 seconde' unless $span; |
94
|
12
|
|
|
|
|
37
|
_render('%s', |
95
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
96
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub interval_exact { |
101
|
31
|
|
|
31
|
0
|
32
|
my $span = $_[0]; # interval, in seconds |
102
|
|
|
|
|
|
|
# precision is ignored |
103
|
31
|
100
|
|
|
|
75
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
50
|
|
|
|
|
|
104
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
105
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
106
|
30
|
|
|
|
|
65
|
_render($direction, |
107
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub interval { |
111
|
86
|
|
|
86
|
0
|
109
|
my $span = $_[0]; # interval, in seconds |
112
|
86
|
|
100
|
|
|
362
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
113
|
86
|
100
|
|
|
|
203
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
100
|
|
|
|
|
|
114
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
115
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
116
|
76
|
|
|
|
|
161
|
_render($direction, |
117
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
118
|
|
|
|
|
|
|
Time::Duration::_separate($span))); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _render { |
123
|
|
|
|
|
|
|
# Make it into French |
124
|
120
|
|
|
120
|
|
4798
|
my $direction = shift @_; |
125
|
600
|
100
|
|
|
|
2778
|
my @wheel = map { |
|
|
100
|
|
|
|
|
|
126
|
120
|
|
|
|
|
162
|
( $_->[1] == 0 ) ? () # zero wheels |
127
|
|
|
|
|
|
|
: $_->[1] . " " . $en2fr{ $_->[0] }[ $_->[1] == 1 ? 0 : 1 ] |
128
|
|
|
|
|
|
|
} @_; |
129
|
|
|
|
|
|
|
|
130
|
120
|
50
|
|
|
|
755
|
return "maintenant" unless @wheel; # sanity |
131
|
|
|
|
|
|
|
|
132
|
120
|
|
|
|
|
119
|
my $result; |
133
|
120
|
100
|
|
|
|
231
|
if (@wheel == 1) { |
|
|
100
|
|
|
|
|
|
134
|
48
|
|
|
|
|
60
|
$result = $wheel[0]; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif (@wheel == 2) { |
137
|
34
|
|
|
|
|
53
|
$result = "$wheel[0] et $wheel[1]"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
38
|
|
|
|
|
62
|
$wheel[-1] = "et $wheel[-1]"; |
141
|
38
|
|
|
|
|
158
|
$result = join q{, }, @wheel; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
120
|
|
|
|
|
904
|
return sprintf($direction, $result); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |