line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::end_week; |
2
|
2
|
|
|
2
|
|
1022
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
112370
|
|
|
2
|
|
|
|
|
10
|
|
3
|
2
|
|
|
2
|
|
353
|
use Moo; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
9
|
|
4
|
2
|
|
|
2
|
|
409
|
use Catmandu::Util qw(:is :check :array); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
699
|
|
5
|
2
|
|
|
2
|
|
499
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
309982
|
|
|
2
|
|
|
|
|
9
|
|
6
|
2
|
|
|
2
|
|
124
|
use DateTime::TimeZone; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
34
|
|
7
|
2
|
|
|
2
|
|
7
|
use DateTime; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
798
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.0131"; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Catmandu::Fix::Base'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has path => ( |
14
|
|
|
|
|
|
|
is => 'ro' , |
15
|
|
|
|
|
|
|
required => 1 |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
has add => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => sub { check_integer($_[0]); }, |
20
|
|
|
|
|
|
|
required => 0, |
21
|
|
|
|
|
|
|
lazy => 1, |
22
|
|
|
|
|
|
|
default => sub { 0; } |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
has time_zone => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
isa => sub { |
28
|
|
|
|
|
|
|
check_string($_[0]); |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
default => sub { |
31
|
|
|
|
|
|
|
"UTC" |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
has pattern => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
required => 1, |
37
|
|
|
|
|
|
|
isa => sub { |
38
|
|
|
|
|
|
|
check_string($_[0]); |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
"%FT%T.%NZ" |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
around BUILDARGS => sub { |
46
|
|
|
|
|
|
|
my($orig,$class,$path,%args) = @_; |
47
|
|
|
|
|
|
|
$orig->($class, |
48
|
|
|
|
|
|
|
path => $path, |
49
|
|
|
|
|
|
|
%args |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub emit { |
54
|
2
|
|
|
2
|
0
|
5326
|
my($self,$fixer) = @_; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
15
|
my $path = $fixer->split_path($self->path()); |
57
|
|
|
|
|
|
|
my $end_week = $fixer->capture(sub{ |
58
|
2
|
|
|
2
|
|
5542
|
my $skip = shift; |
59
|
|
|
|
|
|
|
#we need to set the time zone first before doing any math! |
60
|
2
|
|
|
|
|
14
|
my $d = DateTime->now->set_time_zone($self->time_zone)->truncate(to => "day"); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
969
|
my $wday = $d->day_of_week; |
63
|
2
|
50
|
|
|
|
10
|
unless($wday == 0){ |
64
|
2
|
|
|
|
|
7
|
$d->add(days => 7 - $wday); |
65
|
|
|
|
|
|
|
} |
66
|
2
|
50
|
|
|
|
1641
|
if(is_integer($skip)){ |
67
|
2
|
|
|
|
|
26
|
$d->add(weeks => $skip); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
804
|
$d; |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
|
|
55
|
}); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$fixer->emit_create_path($fixer->var,$path,sub{ |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
2
|
|
171
|
my $var = shift; |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
6
|
my $d = $fixer->generate_var(); |
79
|
2
|
|
|
|
|
61
|
my $p = $fixer->emit_declare_vars($d); |
80
|
2
|
|
|
|
|
27
|
$p .= " $d = ${end_week}->(".$self->add().");"; |
81
|
2
|
|
|
|
|
311
|
$p .= " ${var} = DateTime::Format::Strptime::strftime('".$self->pattern()."',$d);"; |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
6
|
$p; |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
180
|
}); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Catmandu::Fix::end_week - Catmandu Fix for retrieving date string for end of the current week |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SYNOPSIS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#get end of the week in time zone Europe/Brussels |
99
|
|
|
|
|
|
|
end_week('end_week','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels') |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#get end of the week, within two weeks, in time zone Europe/Brussels |
102
|
|
|
|
|
|
|
end_week('end_week','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels', 'add' => 2) |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHOR |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Nicolas Franck, C<< <nicolas.franck at ugent.be> >> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 SEE ALSO |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<Catmandu::Fix> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |