line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
72
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
872
|
use Test::More qw(no_plan); |
|
1
|
|
|
|
|
14034
|
|
|
1
|
|
|
|
|
8
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
652
|
use DateTimeX::ISO8601::Interval; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
4304
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
subtest single_interval => sub { |
8
|
1
|
|
|
1
|
|
763
|
my $interval = DateTimeX::ISO8601::Interval->parse('2013-04-15/17'); |
9
|
1
|
|
|
|
|
6
|
my $iter = $interval->iterator; |
10
|
1
|
|
|
|
|
6
|
my $sub_interval = $iter->(); |
11
|
1
|
|
|
|
|
3
|
is $sub_interval->start->ymd, "2013-04-15", "expected start date"; |
12
|
1
|
|
|
|
|
339
|
my $second = $iter->(); |
13
|
1
|
|
|
|
|
4
|
is $second, undef, 'no more dates'; |
14
|
1
|
|
|
|
|
11
|
}; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
subtest 'date precision' => sub { |
17
|
1
|
|
|
1
|
|
420
|
my $interval = DateTimeX::ISO8601::Interval->parse('2013-04-15/17'); |
18
|
1
|
|
|
|
|
4
|
my $iter = $interval->iterator(); |
19
|
1
|
|
|
|
|
3
|
my $range = $iter->(); |
20
|
1
|
|
|
|
|
4
|
is $range->start->ymd, "2013-04-15", "expected start date"; |
21
|
1
|
|
|
|
|
305
|
is $range->end->ymd, "2013-04-18", "expected end date is the following date"; |
22
|
1
|
|
|
|
|
296
|
is $iter->(), undef, 'no more dates'; |
23
|
1
|
|
|
|
|
982
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
subtest 'repeat X times (daily)' => sub { |
26
|
1
|
|
|
1
|
|
409
|
my $interval = DateTimeX::ISO8601::Interval->parse('R10/2013-04-15/P1D'); |
27
|
1
|
|
|
|
|
4
|
my $iter = $interval->iterator; |
28
|
1
|
|
|
|
|
3
|
my @dates = grep { defined } map { $iter->() } 1..15; |
|
10
|
|
|
|
|
11
|
|
|
15
|
|
|
|
|
25
|
|
29
|
1
|
|
|
|
|
5
|
is @dates, 10, 'ten dates returned'; |
30
|
1
|
|
|
|
|
469
|
is_deeply [map { $_->start->day } @dates], [15..24], 'correct interval'; |
|
10
|
|
|
|
|
234
|
|
31
|
1
|
|
|
|
|
869
|
}; |
32
|
|
|
|
|
|
|
subtest 'repeat X times (monthly, end of month)' => sub { |
33
|
1
|
|
|
1
|
|
482
|
my $interval = DateTimeX::ISO8601::Interval->parse('R12/2013-01-31/P1M'); |
34
|
1
|
|
|
|
|
8
|
my $iter = $interval->iterator; |
35
|
1
|
|
|
|
|
3
|
my @dates = grep { defined } map { $iter->() } 1..12; |
|
12
|
|
|
|
|
14
|
|
|
12
|
|
|
|
|
27
|
|
36
|
1
|
|
|
|
|
5
|
is @dates, 12, 'twelve dates returned'; |
37
|
1
|
|
|
|
|
487
|
is_deeply [map { $_->start->ymd } @dates], [qw(2013-01-31 2013-02-28 2013-03-31 2013-04-30 2013-05-31 2013-06-30 2013-07-31 2013-08-31 2013-09-30 2013-10-31 2013-11-30 2013-12-31)], 'correct interval'; |
|
12
|
|
|
|
|
334
|
|
38
|
1
|
|
|
|
|
1265
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
subtest 'repeat X times (monthly + 1 day)' => sub { |
41
|
1
|
|
|
1
|
|
481
|
my $interval = DateTimeX::ISO8601::Interval->parse('R12/2013-01-31/P1M1D'); |
42
|
1
|
|
|
|
|
4
|
my $iter = $interval->iterator; |
43
|
1
|
|
|
|
|
3
|
my @dates = grep { defined } map { $iter->() } 1..12; |
|
12
|
|
|
|
|
13
|
|
|
12
|
|
|
|
|
22
|
|
44
|
1
|
|
|
|
|
6
|
is @dates, 12, 'twelve dates returned'; |
45
|
1
|
|
|
|
|
488
|
is_deeply [ map { $_->start->ymd } @dates ], |
|
12
|
|
|
|
|
314
|
|
46
|
|
|
|
|
|
|
[ qw(2013-01-31 2013-03-01 2013-04-02 2013-05-03 2013-06-04 2013-07-05 2013-08-06 2013-09-07 2013-10-08 2013-11-09 2013-12-10 2014-01-11) |
47
|
|
|
|
|
|
|
], 'correct interval'; |
48
|
1
|
|
|
|
|
1301
|
}; |
49
|
|
|
|
|
|
|
subtest 'repeat N times (1 hour)' => sub { |
50
|
1
|
|
|
1
|
|
529
|
my $interval = DateTimeX::ISO8601::Interval->parse('R/2013-03-10/PT1H', time_zone => 'America/New_York'); |
51
|
1
|
|
|
|
|
5
|
my $iter = $interval->iterator(); |
52
|
1
|
|
|
|
|
3
|
my @intervals = grep { defined } map { $iter->() } 1..24; |
|
24
|
|
|
|
|
25
|
|
|
24
|
|
|
|
|
45
|
|
53
|
1
|
|
|
|
|
5
|
is @intervals, 24, '24 intervals returned'; |
54
|
1
|
|
|
|
|
511
|
foreach my $interval(@intervals) { |
55
|
24
|
|
|
|
|
7918
|
is $interval->duration->hours, 1, 'one hour range: ' . $interval; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
|
|
|
|
1374
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
subtest 'repeat + skip (3 months)' => sub { |
60
|
1
|
|
|
1
|
|
547
|
my $interval = DateTimeX::ISO8601::Interval->parse('R/2013-12-31/P3M', time_zone => 'America/New_York'); |
61
|
1
|
|
|
|
|
6
|
my $iter = $interval->iterator(skip => 4); |
62
|
1
|
|
|
|
|
4
|
my $next = $iter->(); |
63
|
1
|
|
|
|
|
3
|
is "$next", "2014-12-31T00:00:00-0500/2015-03-31T00:00:00-0400", "skips ahead 4 * 3 months"; |
64
|
1
|
|
|
|
|
384
|
$next = $iter->(); |
65
|
1
|
|
|
|
|
8
|
is "$next", "2015-03-31T00:00:00-0400/2015-06-30T00:00:00-0400", "expected following interval"; |
66
|
1
|
|
|
|
|
1341
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
subtest 'repeat X times + skip (1 week)' => sub { |
69
|
1
|
|
|
1
|
|
469
|
my $interval = DateTimeX::ISO8601::Interval->parse('R4/2013-12-31/P3W', time_zone => 'America/New_York'); |
70
|
1
|
|
|
|
|
5
|
my $iter = $interval->iterator(skip => 4); |
71
|
1
|
|
|
|
|
3
|
is $iter->(), undef, 'past the end'; |
72
|
1
|
|
|
|
|
355
|
is $iter->(), undef, 'still past the end'; |
73
|
1
|
|
|
|
|
1019
|
}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
subtest 'repeat X times + steps (12 days)' => sub { |
76
|
1
|
|
|
1
|
|
428
|
my $interval = DateTimeX::ISO8601::Interval->parse('R4/2013-01-01/P12D', time_zone => 'America/New_York'); |
77
|
1
|
|
|
|
|
4
|
my $iter = $interval->iterator; |
78
|
1
|
|
|
|
|
4
|
is $iter->(2)->start->ymd, "2013-01-13", 'no steps'; |
79
|
1
|
|
|
|
|
376
|
is $iter->(1)->start->ymd, "2013-01-25", 'one step'; |
80
|
1
|
|
|
|
|
317
|
is $iter->(2), undef, 'no more left'; |
81
|
1
|
|
|
|
|
936
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
subtest 'after XYZ' => sub { |
84
|
1
|
|
|
1
|
|
533
|
my $interval = DateTimeX::ISO8601::Interval->parse('R/2013-01-01/P1D', time_zone => 'America/New_York'); |
85
|
1
|
|
|
|
|
6
|
my $iter = $interval->iterator(after => DateTime->new(year => 2013, month => 1, day => 15, time_zone => 'America/New_York')); |
86
|
1
|
|
|
|
|
9
|
is $iter->()->start->ymd, '2013-01-15', 'expected next start date'; |
87
|
1
|
|
|
|
|
489
|
is $iter->()->start->ymd, '2013-01-16', 'expected next start date'; |
88
|
1
|
|
|
|
|
1153
|
}; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
subtest 'until date' => sub { |
91
|
1
|
|
|
1
|
|
476
|
my $interval = DateTimeX::ISO8601::Interval->parse('R/2013-01-01/P1D', time_zone => 'America/New_York'); |
92
|
1
|
|
|
|
|
6
|
my $iter = $interval->iterator( |
93
|
|
|
|
|
|
|
after => DateTime->new( |
94
|
|
|
|
|
|
|
year => 2013, |
95
|
|
|
|
|
|
|
month => 1, |
96
|
|
|
|
|
|
|
day => 30, |
97
|
|
|
|
|
|
|
time_zone => 'America/New_York' |
98
|
|
|
|
|
|
|
), |
99
|
|
|
|
|
|
|
until => DateTime->new( |
100
|
|
|
|
|
|
|
year => 2013, |
101
|
|
|
|
|
|
|
month => 2, |
102
|
|
|
|
|
|
|
day => 2, |
103
|
|
|
|
|
|
|
hour => 1, |
104
|
|
|
|
|
|
|
time_zone => 'America/New_York' |
105
|
|
|
|
|
|
|
) |
106
|
|
|
|
|
|
|
); |
107
|
1
|
|
|
|
|
7
|
my @dates = grep { defined } map {$iter->()} 1..5; |
|
4
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
10
|
|
108
|
1
|
|
|
|
|
5
|
is @dates, 3, 'expected number of dates'; |
109
|
1
|
|
|
|
|
474
|
is $dates[0]->start->ymd, '2013-01-30', 'first date'; |
110
|
1
|
|
|
|
|
296
|
is $dates[-1]->start->ymd, '2013-02-01', 'last date'; |
111
|
1
|
|
|
|
|
1108
|
}; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
subtest 'no start/end' => sub { |
114
|
1
|
|
|
1
|
|
485
|
my $interval = DateTimeX::ISO8601::Interval->parse('R/PT1H'); |
115
|
1
|
|
|
|
|
5
|
my $iter = $interval->iterator( |
116
|
|
|
|
|
|
|
after => DateTime->new( year => 2013, month => 12, day => 30, time_zone => 'America/New_York'), |
117
|
|
|
|
|
|
|
until => DateTime->new( year => 2013, month => 12, day => 31, time_zone => 'America/New_York'), |
118
|
|
|
|
|
|
|
); |
119
|
1
|
|
|
|
|
4
|
my @intervals = grep { defined } map { $iter->() } 1..30; |
|
25
|
|
|
|
|
26
|
|
|
30
|
|
|
|
|
62
|
|
120
|
1
|
|
|
|
|
6
|
is @intervals, 24, 'expected number of intervals'; |
121
|
1
|
|
|
|
|
509
|
is $intervals[0]->format, '2013-12-30T00:00:00-0500/2013-12-30T01:00:00-0500', 'expected first interval'; |
122
|
1
|
|
|
|
|
354
|
is $intervals[-1]->format, '2013-12-30T23:00:00-0500/2013-12-31T00:00:00-0500', 'expected last interval'; |
123
|
1
|
|
|
|
|
1140
|
}; |