line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Verbal; |
2
|
|
|
|
|
|
|
# ABSTRACT: Convert time distance to words. |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
231532
|
use strict; |
|
4
|
|
|
|
|
28
|
|
|
4
|
|
|
|
|
111
|
|
5
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
98
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1667
|
use Object::Tiny qw(locale); |
|
4
|
|
|
|
|
993
|
|
|
4
|
|
|
|
|
18
|
|
8
|
4
|
|
|
4
|
|
545
|
use File::Spec; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
77
|
|
9
|
4
|
|
|
4
|
|
1582
|
use Locale::Wolowitz; |
|
4
|
|
|
|
|
32866
|
|
|
4
|
|
|
|
|
1656
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub distance { |
12
|
1529
|
|
|
1529
|
1
|
697916
|
my $self = shift; |
13
|
1529
|
100
|
|
|
|
3337
|
unless (ref($self)) { |
14
|
27
|
|
|
|
|
43
|
unshift(@_, $self); |
15
|
27
|
|
|
|
|
71
|
$self = __PACKAGE__->new; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1529
|
|
|
|
|
2509
|
my ($from_time, $to_time) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1529
|
50
|
33
|
|
|
5022
|
die "The arguments should be (\$from_time, \$to_time), both are required." unless defined($from_time) && defined($to_time); |
21
|
|
|
|
|
|
|
|
22
|
1529
|
|
|
|
|
2248
|
my $delta = abs($to_time - $from_time); |
23
|
|
|
|
|
|
|
|
24
|
1529
|
100
|
|
|
|
2399
|
if ($delta < 30) { |
25
|
11
|
|
|
|
|
24
|
return $self->loc("less then a minute") |
26
|
|
|
|
|
|
|
} |
27
|
1518
|
100
|
|
|
|
2256
|
if ($delta < 90) { |
28
|
9
|
|
|
|
|
21
|
return $self->loc("1 minute"); |
29
|
|
|
|
|
|
|
} |
30
|
1509
|
100
|
|
|
|
2215
|
if ($delta < 3600) { |
31
|
69
|
|
|
|
|
196
|
return $self->loc('%1 minutes', int(0.5+$delta / 60)); |
32
|
|
|
|
|
|
|
} |
33
|
1440
|
100
|
|
|
|
1980
|
if ($delta < 5400) { |
34
|
36
|
|
|
|
|
65
|
return $self->loc("about 1 hour"); |
35
|
|
|
|
|
|
|
} |
36
|
1404
|
100
|
|
|
|
2083
|
if ($delta < 86400) { |
37
|
1383
|
|
|
|
|
3870
|
return $self->loc('%1 hours', int(0.5+ $delta / 3600)); |
38
|
|
|
|
|
|
|
} |
39
|
21
|
100
|
66
|
|
|
72
|
if ($delta >= 86400 && $delta < 86400 * 2) { |
40
|
6
|
|
|
|
|
14
|
return $self->loc("one day"); |
41
|
|
|
|
|
|
|
} |
42
|
15
|
100
|
|
|
|
31
|
if ($delta < 86400 * 365) { |
43
|
5
|
|
|
|
|
16
|
return $self->loc('%1 days', int($delta / 86400)); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
22
|
return $self->loc("over a year"); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub loc { |
50
|
1529
|
|
|
1529
|
0
|
2620
|
my ($self, $msg, @args) = @_; |
51
|
1529
|
|
100
|
|
|
2484
|
return $self->wolowitz->loc( $msg, $self->locale || "en" , @args ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub i18n_dir { |
55
|
31
|
|
|
31
|
0
|
135
|
my ($self, $dir) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $i18n_dir = sub { |
58
|
29
|
|
|
29
|
|
181
|
my @i18n_dir = (File::Spec->splitdir(__FILE__), "i18n"); |
59
|
29
|
|
|
|
|
103
|
$i18n_dir[-2] =~ s/\.pm//; |
60
|
29
|
|
|
|
|
370
|
return File::Spec->catdir(@i18n_dir); |
61
|
31
|
|
|
|
|
121
|
}; |
62
|
|
|
|
|
|
|
|
63
|
31
|
50
|
|
|
|
74
|
if (ref($self)) { |
64
|
31
|
50
|
|
|
|
55
|
if (defined($dir)) { |
65
|
0
|
|
|
|
|
0
|
$self->{i18n_dir} = $dir; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
31
|
100
|
|
|
|
59
|
if (defined($self->{i18n_dir})) { |
69
|
|
|
|
|
|
|
return $self->{i18n_dir} |
70
|
2
|
|
|
|
|
16
|
} |
71
|
|
|
|
|
|
|
|
72
|
29
|
|
|
|
|
44
|
return $self->{i18n_dir} = $i18n_dir->(); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return $i18n_dir->(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub wolowitz { |
79
|
1529
|
|
|
1529
|
0
|
1960
|
my ($self) = @_; |
80
|
1529
|
|
66
|
|
|
2751
|
$self->{wolowitz} ||= Locale::Wolowitz->new( $self->i18n_dir); |
81
|
|
|
|
|
|
|
return $self->{wolowitz} |
82
|
1529
|
|
|
|
|
190914
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |