line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Duration::id; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20615
|
use 5.010001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use base qw(Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
161
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( |
12
|
|
|
|
|
|
|
later later_exact earlier earlier_exact |
13
|
|
|
|
|
|
|
ago ago_exact from_now from_now_exact |
14
|
|
|
|
|
|
|
duration duration_exact concise |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = ("interval", @EXPORT); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
4
|
use constant DEBUG => 0; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
19
|
1
|
|
|
1
|
|
938
|
use Time::Duration (); |
|
1
|
|
|
|
|
1665
|
|
|
1
|
|
|
|
|
786
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %en2id = ( |
22
|
|
|
|
|
|
|
#picosecond => ["nanodetik" , "pd"], |
23
|
|
|
|
|
|
|
#nanosecond => ["nanodetik" , "nd"], |
24
|
|
|
|
|
|
|
#microsecond => ["mikrodetik", "μd"], |
25
|
|
|
|
|
|
|
millisecond => ["milidetik" , "md"], |
26
|
|
|
|
|
|
|
second => ["detik" , "d" ], |
27
|
|
|
|
|
|
|
minute => ["menit" , "m" ], |
28
|
|
|
|
|
|
|
hour => ["jam" , "j" ], |
29
|
|
|
|
|
|
|
day => ["hari" , "h" ], |
30
|
|
|
|
|
|
|
year => ["tahun" , "t" ], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my %short = map { $_->[0] => $_->[1] } values %en2id; |
34
|
|
|
|
|
|
|
my $comp_re = join "|", map { $_->[0] } values %en2id; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub concise ($) { |
38
|
17
|
|
|
17
|
0
|
22
|
my $string = $_[0]; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#print "in : $string\n"; |
41
|
17
|
|
|
|
|
25
|
$string =~ tr/,//d; |
42
|
17
|
|
|
|
|
27
|
$string =~ s/\bdan\b//; |
43
|
17
|
|
|
|
|
158
|
$string =~ s/\b($comp_re)s?\b/$short{$1}/g; |
44
|
17
|
|
|
|
|
87
|
$string =~ s/\s*(\d+)\s*/$1/g; |
45
|
|
|
|
|
|
|
|
46
|
17
|
|
|
|
|
90
|
return $string; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub later { |
50
|
6
|
|
|
6
|
0
|
29
|
interval( $_[0], $_[1], "%s lalu", "%s lagi", "sekarang"); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub later_exact { |
54
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], "%s lalu", "%s lagi", "sekarang"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub earlier { |
58
|
6
|
|
|
6
|
0
|
17
|
interval( $_[0], $_[1], "%s lagi", "%s lalu", "sekarang"); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub earlier_exact { |
62
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], "%s lagi", "%s lalu", "sekarang"); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub ago { |
66
|
6
|
|
|
6
|
0
|
17
|
interval( $_[0], $_[1], '%s lagi', '%s lalu', "sekarang"); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub ago_exact { |
70
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s lagi', '%s lalu', "sekarang"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub from_now { |
74
|
6
|
|
|
6
|
0
|
17
|
interval( $_[0], $_[1], '%s lalu', '%s lagi', "sekarang"); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub from_now_exact { |
78
|
0
|
|
|
0
|
0
|
0
|
interval_exact($_[0], $_[1], '%s lalu', '%s lagi', "sekarang"); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub duration_exact { |
83
|
0
|
|
|
0
|
0
|
0
|
my $span = $_[0]; # interval in seconds |
84
|
0
|
|
0
|
|
|
0
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
85
|
0
|
0
|
|
|
|
0
|
return '0 detik' unless $span; |
86
|
0
|
|
|
|
|
0
|
_render('%s', |
87
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span)); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub duration { |
91
|
10
|
|
|
10
|
0
|
41
|
my $span = $_[0]; # interval in seconds |
92
|
10
|
|
50
|
|
|
64
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
93
|
10
|
100
|
|
|
|
33
|
return '0 detik' unless $span; |
94
|
8
|
|
|
|
|
26
|
_render('%s', |
95
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
96
|
|
|
|
|
|
|
Time::Duration::_separate(abs $span))); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub interval_exact { |
101
|
0
|
|
|
0
|
0
|
0
|
my $span = $_[0]; # interval, in seconds |
102
|
|
|
|
|
|
|
# precision is ignored |
103
|
0
|
0
|
|
|
|
0
|
my $direction = ($span <= -1) ? $_[2] # what a neg number gets |
|
|
0
|
|
|
|
|
|
104
|
|
|
|
|
|
|
: ($span >= 1) ? $_[3] # what a pos number gets |
105
|
|
|
|
|
|
|
: return $_[4]; # what zero gets |
106
|
0
|
|
|
|
|
0
|
_render($direction, |
107
|
|
|
|
|
|
|
Time::Duration::_separate($span)); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub interval { |
111
|
24
|
|
|
24
|
0
|
27
|
my $span = $_[0]; # interval, in seconds |
112
|
24
|
|
50
|
|
|
718
|
my $precision = int($_[1] || 0) || 2; # precision (default: 2) |
113
|
24
|
100
|
|
|
|
76
|
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
|
16
|
|
|
|
|
35
|
_render($direction, |
117
|
|
|
|
|
|
|
Time::Duration::_approximate($precision, |
118
|
|
|
|
|
|
|
Time::Duration::_separate($span))); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _render { |
123
|
|
|
|
|
|
|
# Make it into Indonesian |
124
|
24
|
|
|
24
|
|
945
|
my $direction = shift @_; |
125
|
120
|
100
|
|
|
|
289
|
my @wheel = map { |
126
|
24
|
|
|
|
|
34
|
( $_->[1] == 0 ) ? () # zero wheels |
127
|
|
|
|
|
|
|
: $_->[1] . " " . $en2id{ $_->[0] }[0] |
128
|
|
|
|
|
|
|
} @_; |
129
|
|
|
|
|
|
|
|
130
|
24
|
50
|
|
|
|
88
|
return "baru saja" unless @wheel; # sanity |
131
|
|
|
|
|
|
|
|
132
|
24
|
|
|
|
|
25
|
my $result; |
133
|
24
|
100
|
|
|
|
44
|
if (@wheel == 1) { |
|
|
50
|
|
|
|
|
|
134
|
22
|
|
|
|
|
29
|
$result = $wheel[0]; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
elsif (@wheel == 2) { |
137
|
2
|
|
|
|
|
6
|
$result = "$wheel[0] $wheel[1]"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
else { |
140
|
|
|
|
|
|
|
#$wheel[-1] = "dan $wheel[-1]"; |
141
|
0
|
|
|
|
|
0
|
$result = join q{, }, @wheel; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
24
|
|
|
|
|
141
|
return sprintf($direction, $result); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
# ABSTRACT: Describe time duration in Indonesian |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
__END__ |