line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Verbal; |
2
|
|
|
|
|
|
|
# ABSTRACT: Convert time distance to words. |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
963894
|
use strict; |
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
120
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
111
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2015
|
use Object::Tiny qw(locale); |
|
4
|
|
|
|
|
1413
|
|
|
4
|
|
|
|
|
24
|
|
8
|
4
|
|
|
4
|
|
700
|
use File::Spec; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
90
|
|
9
|
4
|
|
|
4
|
|
2057
|
use Locale::Wolowitz; |
|
4
|
|
|
|
|
31616
|
|
|
4
|
|
|
|
|
2103
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub distance { |
12
|
1529
|
|
|
1529
|
1
|
682593
|
my $self = shift; |
13
|
1529
|
100
|
|
|
|
4077
|
unless (ref($self)) { |
14
|
27
|
|
|
|
|
58
|
unshift(@_, $self); |
15
|
27
|
|
|
|
|
108
|
$self = __PACKAGE__->new; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1529
|
|
|
|
|
2878
|
my ($from_time, $to_time) = @_; |
19
|
|
|
|
|
|
|
|
20
|
1529
|
50
|
33
|
|
|
5801
|
die "The arguments should be (\$from_time, \$to_time), both are required." unless defined($from_time) && defined($to_time); |
21
|
|
|
|
|
|
|
|
22
|
1529
|
|
|
|
|
2730
|
my $delta = abs($to_time - $from_time); |
23
|
|
|
|
|
|
|
|
24
|
1529
|
100
|
|
|
|
2820
|
if ($delta < 30) { |
25
|
11
|
|
|
|
|
31
|
return $self->loc("less then a minute") |
26
|
|
|
|
|
|
|
} |
27
|
1518
|
100
|
|
|
|
2856
|
if ($delta < 90) { |
28
|
9
|
|
|
|
|
33
|
return $self->loc("1 minute"); |
29
|
|
|
|
|
|
|
} |
30
|
1509
|
100
|
|
|
|
2748
|
if ($delta < 3600) { |
31
|
69
|
|
|
|
|
235
|
return $self->loc('%1 minutes', int(0.5+$delta / 60)); |
32
|
|
|
|
|
|
|
} |
33
|
1440
|
100
|
|
|
|
2674
|
if ($delta < 5400) { |
34
|
36
|
|
|
|
|
97
|
return $self->loc("about 1 hour"); |
35
|
|
|
|
|
|
|
} |
36
|
1404
|
100
|
|
|
|
2465
|
if ($delta < 86400) { |
37
|
1383
|
|
|
|
|
4910
|
return $self->loc('%1 hours', int(0.5+ $delta / 3600)); |
38
|
|
|
|
|
|
|
} |
39
|
21
|
100
|
66
|
|
|
80
|
if ($delta >= 86400 && $delta < 86400 * 2) { |
40
|
6
|
|
|
|
|
19
|
return $self->loc("one day"); |
41
|
|
|
|
|
|
|
} |
42
|
15
|
100
|
|
|
|
38
|
if ($delta < 86400 * 365) { |
43
|
5
|
|
|
|
|
25
|
return $self->loc('%1 days', int($delta / 86400)); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
32
|
return $self->loc("over a year"); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub loc { |
50
|
1529
|
|
|
1529
|
0
|
3427
|
my ($self, $msg, @args) = @_; |
51
|
1529
|
|
100
|
|
|
2643
|
return $self->wolowitz->loc( $msg, $self->locale || "en" , @args ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub i18n_dir { |
55
|
31
|
|
|
31
|
0
|
6438
|
my ($self, $dir) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $i18n_dir = sub { |
58
|
29
|
|
|
29
|
|
229
|
my @i18n_dir = (File::Spec->splitdir(__FILE__), "i18n"); |
59
|
29
|
|
|
|
|
123
|
$i18n_dir[-2] =~ s/\.pm//; |
60
|
29
|
|
|
|
|
466
|
return File::Spec->catdir(@i18n_dir); |
61
|
31
|
|
|
|
|
156
|
}; |
62
|
|
|
|
|
|
|
|
63
|
31
|
50
|
|
|
|
89
|
if (ref($self)) { |
64
|
31
|
50
|
|
|
|
69
|
if (defined($dir)) { |
65
|
0
|
|
|
|
|
0
|
$self->{i18n_dir} = $dir; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
31
|
100
|
|
|
|
70
|
if (defined($self->{i18n_dir})) { |
69
|
|
|
|
|
|
|
return $self->{i18n_dir} |
70
|
2
|
|
|
|
|
22
|
} |
71
|
|
|
|
|
|
|
|
72
|
29
|
|
|
|
|
48
|
return $self->{i18n_dir} = $i18n_dir->(); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return $i18n_dir->(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub wolowitz { |
79
|
1529
|
|
|
1529
|
0
|
2388
|
my ($self) = @_; |
80
|
1529
|
|
66
|
|
|
3424
|
$self->{wolowitz} ||= Locale::Wolowitz->new( $self->i18n_dir); |
81
|
|
|
|
|
|
|
return $self->{wolowitz} |
82
|
1529
|
|
|
|
|
236773
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
__END__ |