line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::start_week; |
2
|
2
|
|
|
2
|
|
947
|
use Catmandu::Sane; |
|
2
|
|
|
|
|
110576
|
|
|
2
|
|
|
|
|
11
|
|
3
|
2
|
|
|
2
|
|
356
|
use Moo; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
7
|
|
4
|
2
|
|
|
2
|
|
426
|
use Catmandu::Util qw(:is :check :array); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
701
|
|
5
|
2
|
|
|
2
|
|
536
|
use DateTime::Format::Strptime; |
|
2
|
|
|
|
|
298227
|
|
|
2
|
|
|
|
|
10
|
|
6
|
2
|
|
|
2
|
|
146
|
use DateTime::TimeZone; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
34
|
|
7
|
2
|
|
|
2
|
|
7
|
use DateTime; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
818
|
|
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
|
4888
|
my($self,$fixer) = @_; |
55
|
|
|
|
|
|
|
|
56
|
2
|
|
|
|
|
11
|
my $path = $fixer->split_path($self->path()); |
57
|
|
|
|
|
|
|
my $start_week = $fixer->capture(sub{ |
58
|
2
|
|
|
2
|
|
5266
|
my $skip = shift; |
59
|
|
|
|
|
|
|
#we need to set the time zone first before doing any math! |
60
|
2
|
|
|
|
|
13
|
my $d = DateTime->now->set_time_zone($self->time_zone)->truncate(to => "day"); |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
879
|
my $wday = $d->day_of_week; |
63
|
|
|
|
|
|
|
|
64
|
2
|
50
|
|
|
|
9
|
unless($wday == 0){ |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
9
|
$d->subtract(days => $wday - 1); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
}else{ |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
$d->subtract(days => 6); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
1391
|
if(is_integer($skip)){ |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
24
|
$d->add(weeks => $skip); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
600
|
$d; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
47
|
}); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$fixer->emit_create_path($fixer->var,$path,sub{ |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
2
|
|
134
|
my $var = shift; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
7
|
my $d = $fixer->generate_var(); |
89
|
2
|
|
|
|
|
62
|
my $p = $fixer->emit_declare_vars($d); |
90
|
2
|
|
|
|
|
28
|
$p .= " $d = ${start_week}->(".$self->add().");"; |
91
|
2
|
|
|
|
|
309
|
$p .= " ${var} = DateTime::Format::Strptime::strftime('".$self->pattern()."',$d);"; |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
6
|
$p; |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
121
|
}); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Catmandu::Fix::start_week - Catmandu Fix for retrieving date string for start of the current week |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SYNOPSIS |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#get start of the week in time zone Europe/Brussels |
109
|
|
|
|
|
|
|
start_week('start_week','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels') |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#get start of the week, within 2 weeks, in time zone Europe/Brussels |
112
|
|
|
|
|
|
|
start_week('start_week','pattern' => '%Y-%m-%dT%H:%M:SZ','time_zone' => 'Europe/Brussels', 'add' => 2) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Nicolas Franck, C<< <nicolas.franck at ugent.be> >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<Catmandu::Fix> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |