line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DTL::Fast::Filter::Timesince; |
2
|
3
|
|
|
3
|
|
1191
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
67
|
|
3
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
16
|
|
4
|
3
|
|
|
3
|
|
56
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
92
|
|
5
|
3
|
|
|
3
|
|
13
|
use parent 'DTL::Fast::Filter'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$DTL::Fast::FILTER_HANDLERS{timesince} = __PACKAGE__; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $MAXSTEPS = 2; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @LAPSE = ( |
12
|
|
|
|
|
|
|
[ 'minute', 60 ] |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
unshift @LAPSE, [ 'hour', $LAPSE[0]->[1] * 60 ]; |
16
|
|
|
|
|
|
|
unshift @LAPSE, [ 'day', $LAPSE[0]->[1] * 24 ]; |
17
|
|
|
|
|
|
|
unshift @LAPSE, [ 'week', $LAPSE[0]->[1] * 7 ]; |
18
|
|
|
|
|
|
|
unshift @LAPSE, [ 'month', $LAPSE[1]->[1] * 30 ]; |
19
|
|
|
|
|
|
|
unshift @LAPSE, [ 'year', $LAPSE[2]->[1] * 365 ]; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#@Override |
23
|
|
|
|
|
|
|
#@todo make pre-defined formats from Django |
24
|
|
|
|
|
|
|
sub parse_parameters |
25
|
|
|
|
|
|
|
{ |
26
|
44
|
|
|
44
|
0
|
66
|
my $self = shift; |
27
|
22
|
|
|
|
|
78
|
push @{$self->{parameter}}, DTL::Fast::Variable->new(time) |
28
|
44
|
100
|
|
|
|
66
|
if (not scalar @{$self->{parameter}}); |
|
44
|
|
|
|
|
117
|
|
29
|
44
|
|
|
|
|
91
|
$self->{time} = $self->{parameter}->[0]; |
30
|
44
|
|
|
|
|
119
|
$self->{suffix} = DTL::Fast::Variable->new('s'); # this is pluralize related |
31
|
|
|
|
|
|
|
|
32
|
44
|
|
|
|
|
136
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#@Override |
36
|
|
|
|
|
|
|
sub filter |
37
|
|
|
|
|
|
|
{ |
38
|
44
|
|
|
44
|
0
|
67
|
my $self = shift; # self |
39
|
44
|
|
|
|
|
63
|
shift; # filter_manager |
40
|
44
|
|
|
|
|
58
|
my $value = shift; |
41
|
44
|
|
|
|
|
61
|
my $context = shift; |
42
|
|
|
|
|
|
|
|
43
|
44
|
|
|
|
|
113
|
my $time = $self->{time}->render($context); |
44
|
|
|
|
|
|
|
|
45
|
44
|
|
|
|
|
166
|
return $self->time_diff($time - $value); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub time_diff |
49
|
|
|
|
|
|
|
{ |
50
|
44
|
|
|
44
|
0
|
74
|
my $self = shift; |
51
|
44
|
|
|
|
|
77
|
my $diff = shift; |
52
|
44
|
|
|
|
|
86
|
my @diffs = (); |
53
|
|
|
|
|
|
|
|
54
|
44
|
50
|
|
|
|
102
|
if ($diff) |
55
|
|
|
|
|
|
|
{ |
56
|
44
|
|
|
|
|
75
|
foreach my $lapse (@LAPSE) |
57
|
|
|
|
|
|
|
{ |
58
|
236
|
100
|
|
|
|
508
|
if ($diff >= $lapse->[1]) |
59
|
|
|
|
|
|
|
{ |
60
|
64
|
|
|
|
|
135
|
my $val = int( $diff / $lapse->[1]); |
61
|
64
|
|
|
|
|
99
|
$diff = $diff % $lapse->[1]; |
62
|
|
|
|
|
|
|
push @diffs, sprintf( '%d %s%s' |
63
|
|
|
|
|
|
|
, $val // 'undef' |
64
|
|
|
|
|
|
|
, $lapse->[0] // 'undef' |
65
|
|
|
|
|
|
|
, |
66
|
64
|
|
50
|
|
|
1199
|
($DTL::Fast::FILTER_HANDLERS{pluralize} // require DTL::Fast::Filter::Pluralize && 'DTL::Fast::Filter::Pluralize')->pluralize( |
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
|
|
|
|
$val, [ 's' ]) |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
64
|
100
|
|
|
|
185
|
if (scalar @diffs == $MAXSTEPS) |
71
|
|
|
|
|
|
|
{ |
72
|
24
|
|
|
|
|
42
|
last; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
44
|
|
|
|
|
173
|
return join ', ', @diffs; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |