|
1 |
use Test::More tests => 50;
|
|
2 |
|
|
3 |
use lib 't';
|
|
4 |
|
|
5 |
use Data::Dumper;
|
|
6 |
|
|
7 |
use DateTime;
|
|
8 |
use_ok 'SL::Helper::DateTime';
|
|
9 |
|
|
10 |
sub mon { DateTime->new(year => 2014, month => 6, day => 23) }
|
|
11 |
sub tue { DateTime->new(year => 2014, month => 6, day => 24) }
|
|
12 |
sub wed { DateTime->new(year => 2014, month => 6, day => 25) }
|
|
13 |
sub thu { DateTime->new(year => 2014, month => 6, day => 26) }
|
|
14 |
sub fri { DateTime->new(year => 2014, month => 6, day => 27) }
|
|
15 |
sub sat { DateTime->new(year => 2014, month => 6, day => 28) }
|
|
16 |
sub sun { DateTime->new(year => 2014, month => 6, day => 29) }
|
|
17 |
|
|
18 |
|
|
19 |
is mon->add_businessdays(days => 5)->day_of_week, 1, "mon + 5 => mon";
|
|
20 |
is mon->add_businessdays(days => 12)->day_of_week, 3, "mon + 12 => wed";
|
|
21 |
is fri->add_businessdays(days => 2)->day_of_week, 2, "fri + 2 => tue";
|
|
22 |
is tue->add_businessdays(days => 9)->day_of_week, 1, "tue + 9 => mon";
|
|
23 |
is tue->add_businessdays(days => 8)->day_of_week, 5, "tue + 8 => fri";
|
|
24 |
|
|
25 |
# same with 6day week
|
|
26 |
is mon->add_businessdays(businessweek => 6, days => 5)->day_of_week, 6, "mon + 5 => sat (6dw)";
|
|
27 |
is mon->add_businessdays(businessweek => 6, days => 12)->day_of_week, 1, "mon + 12 => mon (6dw)";
|
|
28 |
is fri->add_businessdays(businessweek => 6, days => 2)->day_of_week, 1, "fri + 2 => mon (6dw)";
|
|
29 |
is tue->add_businessdays(businessweek => 6, days => 9)->day_of_week, 5, "tue + 9 => fri (6dw)";
|
|
30 |
is tue->add_businessdays(businessweek => 6, days => 8)->day_of_week, 4, "tue + 8 => thu (6dw)";
|
|
31 |
|
|
32 |
# absolute dates
|
|
33 |
|
|
34 |
is mon->add_businessdays(days => 5), mon->add(days => 7), "mon + 5 => mon (date)";
|
|
35 |
is mon->add_businessdays(days => 12), mon->add(days => 16), "mon + 12 => wed (date)";
|
|
36 |
is fri->add_businessdays(days => 2), fri->add(days => 4), "fri + 2 => tue (date)";
|
|
37 |
is tue->add_businessdays(days => 9), tue->add(days => 13), "tue + 9 => mon (date)";
|
|
38 |
is tue->add_businessdays(days => 8), tue->add(days => 10), "tue + 8 => fri (date)";
|
|
39 |
|
|
40 |
# same with 6day week
|
|
41 |
is mon->add_businessdays(businessweek => 6, days => 5), mon->add(days => 5), "mon + 5 => sat (date) (6dw)";
|
|
42 |
is mon->add_businessdays(businessweek => 6, days => 12), mon->add(days => 14), "mon + 12 => mon (date) (6dw)";
|
|
43 |
is fri->add_businessdays(businessweek => 6, days => 2), fri->add(days => 3), "fri + 2 => mon (date) (6dw)";
|
|
44 |
is tue->add_businessdays(businessweek => 6, days => 9), tue->add(days => 10), "tue + 9 => fri (date) (6dw)";
|
|
45 |
is tue->add_businessdays(businessweek => 6, days => 8), tue->add(days => 9), "tue + 8 => thu (date) (6dw)";
|
|
46 |
|
|
47 |
|
|
48 |
# same with substract
|
|
49 |
|
|
50 |
is mon->subtract_businessdays(days => 5)->day_of_week, 1, "mon - 5 => mon";
|
|
51 |
is mon->subtract_businessdays(days => 12)->day_of_week, 4, "mon - 12 => thu";
|
|
52 |
is fri->subtract_businessdays(days => 2)->day_of_week, 3, "fri - 2 => wed";
|
|
53 |
is tue->subtract_businessdays(days => 9)->day_of_week, 3, "tue - 9 => wed";
|
|
54 |
is tue->subtract_businessdays(days => 8)->day_of_week, 4, "tue - 8 => thu";
|
|
55 |
|
|
56 |
# same with 6day week
|
|
57 |
is mon->subtract_businessdays(businessweek => 6, days => 5)->day_of_week, 2, "mon - 5 => tue (6dw)";
|
|
58 |
is mon->subtract_businessdays(businessweek => 6, days => 12)->day_of_week, 1, "mon - 12 => mon (6dw)";
|
|
59 |
is fri->subtract_businessdays(businessweek => 6, days => 4)->day_of_week, 1, "fri - 4 => mon (6dw)";
|
|
60 |
is tue->subtract_businessdays(businessweek => 6, days => 9)->day_of_week, 5, "tue - 9 => fri (6dw)";
|
|
61 |
is tue->subtract_businessdays(businessweek => 6, days => 8)->day_of_week, 6, "tue - 8 => sat (6dw)";
|
|
62 |
|
|
63 |
# absolute dates
|
|
64 |
|
|
65 |
is mon->subtract_businessdays(days => 5), mon->add(days => -7), "mon - 5 => mon (date)";
|
|
66 |
is mon->subtract_businessdays(days => 12), mon->add(days => -18), "mon - 12 => thu (date)";
|
|
67 |
is fri->subtract_businessdays(days => 2), fri->add(days => -2), "fri - 2 => wed (date)";
|
|
68 |
is tue->subtract_businessdays(days => 9), tue->add(days => -13), "tue - 9 => wed (date)";
|
|
69 |
is tue->subtract_businessdays(days => 8), tue->add(days => -12), "tue - 8 => thu (date)";
|
|
70 |
|
|
71 |
# same with 6day week
|
|
72 |
is mon->subtract_businessdays(businessweek => 6, days => 5), mon->add(days => -6), "mon - 5 => tue (date) (6dw)";
|
|
73 |
is mon->subtract_businessdays(businessweek => 6, days => 12), mon->add(days => -14), "mon - 12 => mon (date) (6dw)";
|
|
74 |
is fri->subtract_businessdays(businessweek => 6, days => 4), fri->add(days => -4), "fri - 4 => mon (date) (6dw)";
|
|
75 |
is tue->subtract_businessdays(businessweek => 6, days => 9), tue->add(days => -11), "tue - 9 => fri (date) (6dw)";
|
|
76 |
is tue->subtract_businessdays(businessweek => 6, days => 8), tue->add(days => -10), "tue - 8 => sat (date) (6dw)";
|
|
77 |
|
|
78 |
# add with negative days?
|
|
79 |
is mon->add_businessdays(businessweek => 6, days => -5), mon->add(days => -6), "mon - 5 => tue (date) (6dw)";
|
|
80 |
is mon->add_businessdays(businessweek => 6, days => -12), mon->add(days => -14), "mon - 12 => mon (date) (6dw)";
|
|
81 |
is fri->add_businessdays(businessweek => 6, days => -4), fri->add(days => -4), "fri - 4 => mon (date) (6dw)";
|
|
82 |
is tue->add_businessdays(businessweek => 6, days => -9), tue->add(days => -11), "tue - 9 => fri (date) (6dw)";
|
|
83 |
is tue->add_businessdays(businessweek => 6, days => -8), tue->add(days => -10), "tue - 8 => sat (date) (6dw)";
|
|
84 |
|
|
85 |
# what if staring date falls into eekend?
|
|
86 |
is sun->add_businessdays(days => 1), sun->add(days => 1), "1 day after sun is mon";
|
|
87 |
is sat->add_businessdays(days => 1), sat->add(days => 2), "1 day after sut is mon";
|
|
88 |
is sun->add_businessdays(days => -1), sun->add(days => -2), "1 day before sun is fri";
|
|
89 |
is sat->add_businessdays(days => -1), sat->add(days => -1), "1 day before sut is fri";
|
DateTime: (add|subtract)_businessdays Funktionen