line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Verbal; |
2
|
|
|
|
|
|
|
# ABSTRACT: Convert time distance to words. |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
64471
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
98
|
|
5
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
95
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1550
|
use Object::Tiny qw(locale); |
|
4
|
|
|
|
|
1067
|
|
|
4
|
|
|
|
|
19
|
|
8
|
4
|
|
|
4
|
|
574
|
use File::Spec; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
77
|
|
9
|
4
|
|
|
4
|
|
1520
|
use Locale::Wolowitz; |
|
4
|
|
|
|
|
33962
|
|
|
4
|
|
|
|
|
1593
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub distance { |
12
|
1525
|
|
|
1525
|
1
|
797855
|
my $self = shift; |
13
|
1525
|
100
|
|
|
|
4875
|
unless (ref($self)) { |
14
|
23
|
|
|
|
|
50
|
unshift(@_, $self); |
15
|
23
|
|
|
|
|
83
|
$self = __PACKAGE__->new; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1525
|
|
|
|
|
3328
|
my ($from_time, $to_time) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1525
|
50
|
33
|
|
|
7185
|
die "The arguments should be (\$from_time, \$to_time), both are required." unless defined($from_time) && defined($to_time); |
21
|
|
|
|
|
|
|
|
22
|
1525
|
|
|
|
|
3089
|
my $delta = abs($to_time - $from_time); |
23
|
|
|
|
|
|
|
|
24
|
1525
|
100
|
|
|
|
3622
|
if ($delta < 30) { |
25
|
11
|
|
|
|
|
37
|
return $self->loc("less then a minute") |
26
|
|
|
|
|
|
|
} |
27
|
1514
|
100
|
|
|
|
3319
|
if ($delta < 90) { |
28
|
9
|
|
|
|
|
24
|
return $self->loc("1 minute"); |
29
|
|
|
|
|
|
|
} |
30
|
1505
|
100
|
|
|
|
3174
|
if ($delta < 3600) { |
31
|
69
|
|
|
|
|
221
|
return $self->loc('%1 minutes', int(0.5+$delta / 60)); |
32
|
|
|
|
|
|
|
} |
33
|
1436
|
100
|
|
|
|
3010
|
if ($delta < 5400) { |
34
|
35
|
|
|
|
|
80
|
return $self->loc("about 1 hour"); |
35
|
|
|
|
|
|
|
} |
36
|
1401
|
100
|
|
|
|
3050
|
if ($delta < 86400) { |
37
|
1381
|
|
|
|
|
4769
|
return $self->loc('%1 hours', int(0.5+ $delta / 3600)); |
38
|
|
|
|
|
|
|
} |
39
|
20
|
100
|
66
|
|
|
96
|
if ($delta > 86400 && $delta < 86400 * 2) { |
40
|
5
|
|
|
|
|
22
|
return $self->loc("one day"); |
41
|
|
|
|
|
|
|
} |
42
|
15
|
100
|
|
|
|
40
|
if ($delta < 86400 * 365) { |
43
|
5
|
|
|
|
|
22
|
return $self->loc('%1 days', int($delta / 86400)); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
26
|
return $self->loc("over a year"); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub loc { |
50
|
1525
|
|
|
1525
|
0
|
3812
|
my ($self, $msg, @args) = @_; |
51
|
1525
|
|
100
|
|
|
3074
|
return $self->wolowitz->loc( $msg, $self->locale || "en" , @args ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub i18n_dir { |
55
|
27
|
|
|
27
|
0
|
95
|
my ($self, $dir) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $i18n_dir = sub { |
58
|
25
|
|
|
25
|
|
214
|
my @i18n_dir = (File::Spec->splitdir(__FILE__), "i18n"); |
59
|
25
|
|
|
|
|
112
|
$i18n_dir[-2] =~ s/\.pm//; |
60
|
25
|
|
|
|
|
351
|
return File::Spec->catdir(@i18n_dir); |
61
|
27
|
|
|
|
|
153
|
}; |
62
|
|
|
|
|
|
|
|
63
|
27
|
50
|
|
|
|
73
|
if (ref($self)) { |
64
|
27
|
50
|
|
|
|
63
|
if (defined($dir)) { |
65
|
0
|
|
|
|
|
0
|
$self->{i18n_dir} = $dir; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
27
|
100
|
|
|
|
68
|
if (defined($self->{i18n_dir})) { |
69
|
|
|
|
|
|
|
return $self->{i18n_dir} |
70
|
2
|
|
|
|
|
24
|
} |
71
|
|
|
|
|
|
|
|
72
|
25
|
|
|
|
|
52
|
return $self->{i18n_dir} = $i18n_dir->(); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return $i18n_dir->(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub wolowitz { |
79
|
1525
|
|
|
1525
|
0
|
2626
|
my ($self) = @_; |
80
|
1525
|
|
66
|
|
|
3843
|
$self->{wolowitz} ||= Locale::Wolowitz->new( $self->i18n_dir); |
81
|
|
|
|
|
|
|
return $self->{wolowitz} |
82
|
1525
|
|
|
|
|
146805
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |