View | Details | Raw Unified | Return to bug 17015
Collapse All | Expand All

(-)a/t/Calendar.t (-340 lines)
Lines 1-340 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More;
21
use Test::MockModule;
22
23
use DateTime;
24
use DateTime::Duration;
25
use Koha::Caches;
26
use Koha::DateUtils;
27
28
use t::lib::Mocks;
29
30
use Module::Load::Conditional qw/check_install/;
31
32
BEGIN {
33
    if ( check_install( module => 'Test::DBIx::Class' ) ) {
34
        plan tests => 39;
35
    } else {
36
        plan skip_all => "Need Test::DBIx::Class"
37
    }
38
}
39
40
use_ok('Koha::Calendar');
41
42
use Test::DBIx::Class;
43
44
my $db = Test::MockModule->new('Koha::Database');
45
$db->mock(
46
    _new_schema => sub { return Schema(); }
47
);
48
49
# We need to mock the C4::Context->preference method for
50
# simplicity and re-usability of the session definition. Any
51
# syspref fits for syspref-agnostic tests.
52
my $module_context = new Test::MockModule('C4::Context');
53
$module_context->mock(
54
    'preference',
55
    sub {
56
        return 'Calendar';
57
    }
58
);
59
60
fixtures_ok [
61
    # weekly holidays
62
    RepeatableHoliday => [
63
        [ qw( branchcode day month weekday title description) ],
64
        [ 'MPL', undef, undef, 0, '', '' ], # sundays
65
        [ 'MPL', undef, undef, 6, '', '' ],# saturdays
66
        [ 'MPL', 1, 1, undef, '', ''], # new year's day
67
        [ 'MPL', 25, 12, undef, '', ''], # chrismas
68
    ],
69
    # exception holidays
70
    SpecialHoliday => [
71
        [qw( branchcode day month year title description isexception )],
72
        [ 'MPL', 11, 11, 2012, '', '', 1 ],    # sunday exception
73
        [ 'MPL', 1,  6,  2011, '', '', 0 ],
74
        [ 'MPL', 4,  7,  2012, '', '', 0 ],
75
        [ 'CPL', 6,  8,  2012, '', '', 0 ],
76
      ],
77
], "add fixtures";
78
79
my $cache = Koha::Caches->get_instance();
80
$cache->clear_from_cache( 'single_holidays' ) ;
81
$cache->clear_from_cache( 'exception_holidays' ) ;
82
83
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
84
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
85
86
isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' );
87
88
my $saturday = DateTime->new(
89
    year      => 2012,
90
    month     => 11,
91
    day       => 24,
92
);
93
94
my $sunday = DateTime->new(
95
    year      => 2012,
96
    month     => 11,
97
    day       => 25,
98
);
99
100
my $monday = DateTime->new(
101
    year      => 2012,
102
    month     => 11,
103
    day       => 26,
104
);
105
106
my $new_year = DateTime->new(
107
    year        => 2013,
108
    month       => 1,
109
    day         => 1,
110
);
111
112
my $single_holiday = DateTime->new(
113
    year      => 2011,
114
    month     => 6,
115
    day       => 1,
116
);    # should be a holiday
117
118
my $notspecial = DateTime->new(
119
    year      => 2011,
120
    month     => 6,
121
    day       => 2
122
);    # should NOT be a holiday
123
124
my $sunday_exception = DateTime->new(
125
    year      => 2012,
126
    month     => 11,
127
    day       => 11
128
);
129
130
my $day_after_christmas = DateTime->new(
131
    year    => 2012,
132
    month   => 12,
133
    day     => 26
134
);  # for testing negative addDate
135
136
my $holiday_for_another_branch = DateTime->new(
137
    year => 2012,
138
    month => 8,
139
    day => 6, # This is a monday
140
);
141
142
{   # Syspref-agnostic tests
143
    is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
144
    is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
145
    is ( $monday->day_of_week, 1, '\'$monday\' is actually a monday (1st day of week)');
146
    is ( $cal->is_holiday($saturday), 1, 'Saturday is a closed day' );
147
    is ( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' );
148
    is ( $cal->is_holiday($monday), 0, 'Monday is not a closed day' );
149
    is ( $cal->is_holiday($new_year), 1, 'Month/Day closed day test (New year\'s day)' );
150
    is ( $cal->is_holiday($single_holiday), 1, 'Single holiday closed day test' );
151
    is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' );
152
    is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
153
    is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' );
154
}
155
156
{   # Bugzilla #8966 - is_holiday truncates referenced date
157
    my $later_dt = DateTime->new(    # Monday
158
        year      => 2012,
159
        month     => 9,
160
        day       => 17,
161
        hour      => 17,
162
        minute    => 30,
163
        time_zone => 'Europe/London',
164
    );
165
166
167
    is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' );
168
    cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
169
}
170
171
{   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
172
    my $single_holiday_time = DateTime->new(
173
        year  => 2011,
174
        month => 6,
175
        day   => 1,
176
        hour  => 11,
177
        minute  => 2
178
    );
179
180
    is( $cal->is_holiday($single_holiday_time),
181
        $cal->is_holiday($single_holiday) ,
182
        'bz-8800 is_holiday should truncate the date for holiday validation' );
183
}
184
185
    my $one_day_dur = DateTime::Duration->new( days => 1 );
186
    my $two_day_dur = DateTime::Duration->new( days => 2 );
187
    my $seven_day_dur = DateTime::Duration->new( days => 7 );
188
189
    my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday
190
191
    my $test_dt = DateTime->new(    # Monday
192
        year      => 2012,
193
        month     => 7,
194
        day       => 23,
195
        hour      => 11,
196
        minute    => 53,
197
    );
198
199
    my $later_dt = DateTime->new(    # Monday
200
        year      => 2012,
201
        month     => 9,
202
        day       => 17,
203
        hour      => 17,
204
        minute    => 30,
205
        time_zone => 'Europe/London',
206
    );
207
208
{    ## 'Datedue' tests
209
210
    $module_context->unmock('preference');
211
    $module_context->mock(
212
        'preference',
213
        sub {
214
            return 'Datedue';
215
        }
216
    );
217
218
    $cal = Koha::Calendar->new( branchcode => 'MPL' );
219
220
    is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday
221
        dt_from_string('2012-07-05','iso'),
222
        'Single day add (Datedue, matches holiday, shift)' );
223
224
    is($cal->addDate( $dt, $two_day_dur, 'days' ),
225
        dt_from_string('2012-07-05','iso'),
226
        'Two days add, skips holiday (Datedue)' );
227
228
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
229
        '2012-07-30T11:53:00',
230
        'Add 7 days (Datedue)' );
231
232
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
233
        'addDate skips closed Sunday (Datedue)' );
234
235
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
236
        'Negative call to addDate (Datedue)' );
237
238
    ## Note that the days_between API says closed days are not considered.
239
    ## This tests are here as an API test.
240
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
241
                '==', 40, 'days_between calculates correctly (Days)' );
242
243
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
244
                '==', 40, 'Test parameter order not relevant (Days)' );
245
}
246
247
{   ## 'Calendar' tests'
248
249
    $module_context->unmock('preference');
250
    $module_context->mock(
251
        'preference',
252
        sub {
253
            return 'Calendar';
254
        }
255
    );
256
257
    $cal = Koha::Calendar->new( branchcode => 'MPL' );
258
259
    $dt = dt_from_string('2012-07-03','iso');
260
261
    is($cal->addDate( $dt, $one_day_dur, 'days' ),
262
        dt_from_string('2012-07-05','iso'),
263
        'Single day add (Calendar)' );
264
265
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
266
       '2012-08-01T11:53:00',
267
       'Add 7 days (Calendar)' );
268
269
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
270
            'addDate skips closed Sunday (Calendar)' );
271
272
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
273
            'Negative call to addDate (Calendar)' );
274
275
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
276
                '==', 40, 'days_between calculates correctly (Calendar)' );
277
278
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
279
                '==', 40, 'Test parameter order not relevant (Calendar)' );
280
}
281
282
283
{   ## 'Days' tests
284
    $module_context->unmock('preference');
285
    $module_context->mock(
286
        'preference',
287
        sub {
288
            return 'Days';
289
        }
290
    );
291
292
    $cal = Koha::Calendar->new( branchcode => 'MPL' );
293
294
    $dt = dt_from_string('2012-07-03','iso');
295
296
    is($cal->addDate( $dt, $one_day_dur, 'days' ),
297
        dt_from_string('2012-07-04','iso'),
298
        'Single day add (Days)' );
299
300
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ),'eq',
301
        '2012-07-30T11:53:00',
302
        'Add 7 days (Days)' );
303
304
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
305
        'addDate doesn\'t skip closed Sunday (Days)' );
306
307
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
308
        'Negative call to addDate (Days)' );
309
310
    ## Note that the days_between API says closed days are not considered.
311
    ## This tests are here as an API test.
312
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
313
                '==', 40, 'days_between calculates correctly (Days)' );
314
315
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
316
                '==', 40, 'Test parameter order not relevant (Days)' );
317
318
}
319
320
{
321
    $cal = Koha::Calendar->new( branchcode => 'CPL' );
322
    is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' );
323
    is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' );
324
}
325
326
subtest 'days_mode parameter' => sub {
327
    plan tests => 2;
328
329
    t::lib::Mocks::mock_preference('useDaysMode', 'Days');
330
    my $cal = Koha::Calendar->new( branchcode => 'CPL' );
331
    is( $cal->{days_mode}, 'Days', q|If not set, days_mode defaults to syspref's value|);
332
333
    $cal = Koha::Calendar->new( branchcode => 'CPL', days_mode => 'Calendar' );
334
    is( $cal->{days_mode}, 'Calendar', q|If set, days_mode is correctly set|);
335
};
336
337
END {
338
    $cache->clear_from_cache( 'single_holidays' ) ;
339
    $cache->clear_from_cache( 'exception_holidays' ) ;
340
};
(-)a/t/db_dependent/Calendar.t (-85 lines)
Lines 1-85 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 6;
21
use t::lib::TestBuilder;
22
23
use DateTime;
24
use Koha::Caches;
25
use Koha::DateUtils;
26
27
use_ok('Koha::Calendar');
28
29
my $schema  = Koha::Database->new->schema;
30
$schema->storage->txn_begin;
31
32
my $today = dt_from_string();
33
my $holiday_dt = $today->clone;
34
$holiday_dt->add(days => 15);
35
36
Koha::Caches->get_instance()->flush_all();
37
38
my $builder = t::lib::TestBuilder->new();
39
my $holiday = $builder->build({
40
    source => 'SpecialHoliday',
41
    value => {
42
        branchcode => 'LIB1',
43
        day => $holiday_dt->day,
44
        month => $holiday_dt->month,
45
        year => $holiday_dt->year,
46
        title => 'My holiday',
47
        isexception => 0
48
    },
49
});
50
51
my $calendar = Koha::Calendar->new( branchcode => 'LIB1');
52
my $forwarded_dt = $calendar->days_forward($today, 10);
53
54
my $expected = $today->clone;
55
$expected->add(days => 10);
56
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days');
57
58
$forwarded_dt = $calendar->days_forward($today, 20);
59
60
$expected->add(days => 11);
61
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday');
62
63
$forwarded_dt = $calendar->days_forward($today, 0);
64
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
65
66
$forwarded_dt = $calendar->days_forward($today, -2);
67
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
68
69
subtest 'crossing_DST' => sub {
70
71
    plan tests => 3;
72
73
    my $tz = DateTime::TimeZone->new( name => 'America/New_York' );
74
    my $start_date = dt_from_string( "2016-03-09 02:29:00",undef,$tz );
75
    my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz );
76
    my $days_between = $calendar->days_between($start_date,$end_date);
77
    is( $days_between->delta_days, 298, "Days calculated correctly" );
78
    $days_between = $calendar->days_between($end_date,$start_date);
79
    is( $days_between->delta_days, 298, "Swapping returns the same" );
80
    my $hours_between = $calendar->hours_between($start_date,$end_date);
81
    is( $hours_between->delta_minutes, 298 * 24 * 60 - 149, "Hours (in minutes) calculated correctly" );
82
83
};
84
85
$schema->storage->txn_rollback();
(-)a/t/db_dependent/Circulation.t (-39 / +36 lines)
Lines 38-43 use C4::Reserves; Link Here
38
use C4::Overdues qw(UpdateFine CalcFine);
38
use C4::Overdues qw(UpdateFine CalcFine);
39
use Koha::DateUtils;
39
use Koha::DateUtils;
40
use Koha::Database;
40
use Koha::Database;
41
use Koha::DiscreteCalendar;
41
use Koha::IssuingRules;
42
use Koha::IssuingRules;
42
use Koha::Items;
43
use Koha::Items;
43
use Koha::Checkouts;
44
use Koha::Checkouts;
Lines 109-116 $mocked_datetime->mock( 'now', sub { return $now_value->clone; } ); Link Here
109
$dbh->{RaiseError} = 1;
110
$dbh->{RaiseError} = 1;
110
111
111
my $cache = Koha::Caches->get_instance();
112
my $cache = Koha::Caches->get_instance();
112
$dbh->do(q|DELETE FROM special_holidays|);
113
$dbh->do(q|DELETE FROM repeatable_holidays|);
114
$cache->clear_from_cache('single_holidays');
113
$cache->clear_from_cache('single_holidays');
115
114
116
# Start with a clean slate
115
# Start with a clean slate
Lines 1850-1865 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1850
    );
1849
    );
1851
    $rule->store();
1850
    $rule->store();
1852
1851
1853
    my $five_days_ago = dt_from_string->subtract( days => 5 );
1852
    my $in_five_days = dt_from_string->add( days => 5 );
1854
    # We want to charge 2 days every day, without grace
1853
    # We want to charge 2 days every day, without grace
1855
    # With 5 days of overdue: 5 * Z
1854
    # With 5 days of overdue: 5 * Z
1856
    my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 );
1855
    my $expected_expiration = dt_from_string->add( days => 5 + ( 5 * 2 ) / 1 );
1857
    test_debarment_on_checkout(
1856
    test_debarment_on_checkout(
1858
        {
1857
        {
1859
            item            => $item_1,
1858
            item            => $item_1,
1860
            library         => $library,
1859
            library         => $library,
1861
            patron          => $patron,
1860
            patron          => $patron,
1862
            due_date        => $five_days_ago,
1861
            return_date     => $in_five_days,
1863
            expiration_date => $expected_expiration,
1862
            expiration_date => $expected_expiration,
1864
        }
1863
        }
1865
    );
1864
    );
Lines 1867-1879 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1867
    # We want to charge 2 days every 2 days, without grace
1866
    # We want to charge 2 days every 2 days, without grace
1868
    # With 5 days of overdue: (5 * 2) / 2
1867
    # With 5 days of overdue: (5 * 2) / 2
1869
    $rule->suspension_chargeperiod(2)->store;
1868
    $rule->suspension_chargeperiod(2)->store;
1870
    $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 );
1869
    $expected_expiration = dt_from_string->add( days => 5 + floor( 5 * 2 ) / 2 );
1871
    test_debarment_on_checkout(
1870
    test_debarment_on_checkout(
1872
        {
1871
        {
1873
            item            => $item_1,
1872
            item            => $item_1,
1874
            library         => $library,
1873
            library         => $library,
1875
            patron          => $patron,
1874
            patron          => $patron,
1876
            due_date        => $five_days_ago,
1875
            return_date     => $in_five_days,
1877
            expiration_date => $expected_expiration,
1876
            expiration_date => $expected_expiration,
1878
        }
1877
        }
1879
    );
1878
    );
Lines 1882-1894 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1882
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1881
    # With 5 days of overdue: ((5-1) / 3 ) * 2
1883
    $rule->suspension_chargeperiod(3)->store;
1882
    $rule->suspension_chargeperiod(3)->store;
1884
    $rule->firstremind(1)->store;
1883
    $rule->firstremind(1)->store;
1885
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1884
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
1886
    test_debarment_on_checkout(
1885
    test_debarment_on_checkout(
1887
        {
1886
        {
1888
            item            => $item_1,
1887
            item            => $item_1,
1889
            library         => $library,
1888
            library         => $library,
1890
            patron          => $patron,
1889
            patron          => $patron,
1891
            due_date        => $five_days_ago,
1890
            return_date     => $in_five_days,
1892
            expiration_date => $expected_expiration,
1891
            expiration_date => $expected_expiration,
1893
        }
1892
        }
1894
    );
1893
    );
Lines 1901-1965 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1901
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1900
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
1902
1901
1903
    # Adding a holiday 2 days ago
1902
    # Adding a holiday 2 days ago
1904
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
1903
    my $calendar = Koha::DiscreteCalendar->new( { branchcode => $library->{branchcode} } );
1905
    my $two_days_ago = dt_from_string->subtract( days => 2 );
1904
    my $in_two_days = dt_from_string->add( days => 2 );
1906
    $calendar->insert_single_holiday(
1905
    $calendar->edit_holiday( {
1907
        day             => $two_days_ago->day,
1906
        title           => 'holidayTest+2d',
1908
        month           => $two_days_ago->month,
1907
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},,
1909
        year            => $two_days_ago->year,
1908
        start_date      => $in_two_days,
1910
        title           => 'holidayTest-2d',
1909
        end_date        => $in_two_days,
1911
        description     => 'holidayDesc 2 days ago'
1910
    } );
1912
    );
1913
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1911
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
1914
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1912
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
1915
    test_debarment_on_checkout(
1913
    test_debarment_on_checkout(
1916
        {
1914
        {
1917
            item            => $item_1,
1915
            item            => $item_1,
1918
            library         => $library,
1916
            library         => $library,
1919
            patron          => $patron,
1917
            patron          => $patron,
1920
            due_date        => $five_days_ago,
1918
            return_date     => $in_five_days,
1921
            expiration_date => $expected_expiration,
1919
            expiration_date => $expected_expiration,
1922
        }
1920
        }
1923
    );
1921
    );
1924
1922
1925
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1923
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
1926
    my $two_days_ahead = dt_from_string->add( days => 2 );
1924
    my $in_seven_days = dt_from_string->add( days => 7 );
1927
    $calendar->insert_single_holiday(
1925
    $calendar->edit_holiday( {
1928
        day             => $two_days_ahead->day,
1926
        title           => 'holidayTest+7d',
1929
        month           => $two_days_ahead->month,
1927
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1930
        year            => $two_days_ahead->year,
1928
        start_date      => $in_seven_days,
1931
        title           => 'holidayTest+2d',
1929
        end_date        => $in_seven_days,
1932
        description     => 'holidayDesc 2 days ahead'
1930
    } );
1933
    );
1934
1931
1935
    # Same as above, but we should skip D+2
1932
    # Same as above, but we should skip D+2
1936
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1933
    $expected_expiration = dt_from_string->add( days => 5 + floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
1937
    test_debarment_on_checkout(
1934
    test_debarment_on_checkout(
1938
        {
1935
        {
1939
            item            => $item_1,
1936
            item            => $item_1,
1940
            library         => $library,
1937
            library         => $library,
1941
            patron          => $patron,
1938
            patron          => $patron,
1942
            due_date        => $five_days_ago,
1939
            return_date     => $in_five_days,
1943
            expiration_date => $expected_expiration,
1940
            expiration_date => $expected_expiration,
1944
        }
1941
        }
1945
    );
1942
    );
1946
1943
1947
    # Adding another holiday, day of expiration date
1944
    # Adding another holiday, day of expiration date
1948
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1945
    my $expected_expiration_dt = dt_from_string($expected_expiration);
1949
    $calendar->insert_single_holiday(
1946
    $calendar->edit_holiday( {
1950
        day             => $expected_expiration_dt->day,
1947
        title           => 'holidayTest+expected_expiration',
1951
        month           => $expected_expiration_dt->month,
1948
        holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
1952
        year            => $expected_expiration_dt->year,
1949
        start_date      => $expected_expiration_dt,
1953
        title           => 'holidayTest_exp',
1950
        end_date        => $expected_expiration_dt,
1954
        description     => 'holidayDesc on expiration date'
1951
    } );
1955
    );
1952
1956
    # Expiration date will be the day after
1953
    # Expiration date will be the day after
1957
    test_debarment_on_checkout(
1954
    test_debarment_on_checkout(
1958
        {
1955
        {
1959
            item            => $item_1,
1956
            item            => $item_1,
1960
            library         => $library,
1957
            library         => $library,
1961
            patron          => $patron,
1958
            patron          => $patron,
1962
            due_date        => $five_days_ago,
1959
            return_date     => $in_five_days,
1963
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1960
            expiration_date => $expected_expiration_dt->clone->add( days => 1 ),
1964
        }
1961
        }
1965
    );
1962
    );
Lines 1970-1976 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
1970
            library         => $library,
1967
            library         => $library,
1971
            patron          => $patron,
1968
            patron          => $patron,
1972
            return_date     => dt_from_string->add(days => 5),
1969
            return_date     => dt_from_string->add(days => 5),
1973
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ),
1970
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) + 1 ), # We add an extra +1 because of the holiday
1974
        }
1971
        }
1975
    );
1972
    );
1976
};
1973
};
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-24 / +23 lines)
Lines 8-14 use DBI; Link Here
8
use DateTime;
8
use DateTime;
9
use t::lib::Mocks;
9
use t::lib::Mocks;
10
use t::lib::TestBuilder;
10
use t::lib::TestBuilder;
11
use C4::Calendar;
11
use Koha::DateUtils;
12
use Koha::DiscreteCalendar;
12
13
13
use_ok('C4::Circulation');
14
use_ok('C4::Circulation');
14
15
Lines 39-50 t::lib::Mocks::mock_preference('useDaysMode', 'Days'); Link Here
39
my $cache           = Koha::Caches->get_instance();
40
my $cache           = Koha::Caches->get_instance();
40
$cache->clear_from_cache('single_holidays');
41
$cache->clear_from_cache('single_holidays');
41
42
42
my $dateexpiry = '2013-01-01';
43
my $dateexpiry = dt_from_string->truncate(to => 'day')->add(days => 30, hours => 23, minutes => 59)->iso8601;
43
44
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
44
my $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
45
my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
45
my $start_date =dt_from_string->truncate(to => 'day')->add(days => 60);
46
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
46
my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
47
is($date, $dateexpiry . 'T23:59:00', 'date expiry');
47
is($date, $dateexpiry, 'date expiry');
48
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
48
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
49
49
50
50
Lines 53-83 t::lib::Mocks::mock_preference('ReturnBeforeExpiry', 1); Link Here
53
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
53
t::lib::Mocks::mock_preference('useDaysMode', 'noDays');
54
54
55
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
55
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
56
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
56
$start_date =dt_from_string->truncate(to => 'day')->add(days => 60);
57
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
57
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
58
is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
58
is($date, $dateexpiry, 'date expiry with useDaysMode to noDays');
59
59
60
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
60
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
61
# useDaysMode different from 'Days', return should forward the dateexpiry.
61
# useDaysMode different from 'Days', return should forward the dateexpiry.
62
my $calendar = C4::Calendar->new(branchcode => $branchcode);
62
my $calendar = Koha::DiscreteCalendar->new({branchcode => $branchcode});
63
$calendar->insert_single_holiday(
63
$calendar->edit_holiday({
64
    day             => 1,
64
    title => 'holidayTest',
65
    month           => 1,
65
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
66
    year            => 2013,
66
    start_date => dt_from_string->add(days=>30),
67
    title           =>'holidayTest',
67
    end_date => dt_from_string->add(days=>30)
68
    description     => 'holidayDesc'
68
});
69
);
70
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
69
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
71
is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
70
is($date, dt_from_string->truncate(to => 'day')->add(days=>29, hours=>23, minutes=>59), 'date expiry should be 2013-01-01 -1 day');
72
$calendar->insert_single_holiday(
71
73
    day             => 31,
72
$calendar->edit_holiday({
74
    month           => 12,
73
    title => 'holidayTest',
75
    year            => 2012,
74
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
76
    title           =>'holidayTest',
75
    start_date => dt_from_string->add(days => 29),
77
    description     => 'holidayDesc'
76
    end_date => dt_from_string->add(days => 29)
78
);
77
});
79
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
78
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
80
is($date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day');
79
is($date, dt_from_string->truncate(to => 'day')->add(days=> 28, hours=>23, minutes=>59), 'date expiry should be 2013-01-01 -2 day');
81
80
82
81
83
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
82
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
(-)a/t/db_dependent/Circulation/CalcFine.t (-22 / +4 lines)
Lines 102-118 subtest 'Test basic functionality' => sub { Link Here
102
        }
102
        }
103
    );
103
    );
104
104
105
    my $start_dt = DateTime->new(
105
    my $start_dt = DateTime->today;
106
        year       => 2000,
106
    my $end_dt = DateTime->today->add(days => 29);
107
        month      => 1,
108
        day        => 1,
109
    );
110
111
    my $end_dt = DateTime->new(
112
        year       => 2000,
113
        month      => 1,
114
        day        => 30,
115
    );
116
107
117
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
108
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
118
109
Lines 143-159 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
143
        }
134
        }
144
    );
135
    );
145
136
146
    my $start_dt = DateTime->new(
137
    my $start_dt = DateTime->today;
147
        year       => 2000,
138
    my $end_dt = DateTime->today->add(days => 29);
148
        month      => 1,
149
        day        => 1,
150
    );
151
152
    my $end_dt = DateTime->new(
153
        year       => 2000,
154
        month      => 1,
155
        day        => 30,
156
    );
157
139
158
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
140
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
159
141
(-)a/t/db_dependent/DiscreteCalendar.t (+462 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Test::More tests => 50;
22
use Test::MockModule;
23
24
use C4::Context;
25
use C4::Output;
26
use Koha::DateUtils;
27
use Koha::DiscreteCalendar;
28
29
30
my $module_context = new Test::MockModule('C4::Context');
31
my $today = DateTime->today;
32
my $schema = Koha::Database->new->schema;
33
$schema->storage->txn_begin;
34
35
my $branch1 = "Library1";
36
my $branch2 = "Library2";
37
38
$schema->resultset('DiscreteCalendar')->search({
39
    branchcode  =>''
40
})->update_all({
41
    is_opened    => 1,
42
    holiday_type => '',
43
    note        => '',
44
    open_hour    => '08:00:00',
45
    close_hour   => '16:00:00'
46
});
47
48
#Added entries for the branches.
49
Koha::DiscreteCalendar->add_new_branch('', $branch1);
50
Koha::DiscreteCalendar->add_new_branch('', $branch2);
51
52
isnt($branch1,'', "First branch to do tests. BranchCode => $branch1");
53
isnt($branch2,'', "Second branch to do tests. BranchCode => $branch2");
54
55
#2 Calendars to make sure branches are treated separately.
56
my $calendar = Koha::DiscreteCalendar->new({branchcode => $branch1});
57
my $calendar2 = Koha::DiscreteCalendar->new({branchcode => $branch2});
58
59
my $unique_holiday = DateTime->today;
60
$calendar->edit_holiday({
61
    title => "Single holiday Today",
62
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
63
    start_date=>$unique_holiday,
64
    end_date=>$unique_holiday
65
});
66
is($calendar->is_opened($unique_holiday), 0, "Branch closed today : $unique_holiday");
67
68
my @unique_holidays = $calendar->get_unique_holidays();
69
is(scalar @unique_holidays, 1, "Set of exception holidays at 1");
70
71
my $yesterday = DateTime->today->subtract(days => 1);
72
$calendar->edit_holiday({
73
    title => "Single holiday Today",
74
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
75
    start_date => $yesterday,
76
    end_date => $yesterday
77
});
78
is($calendar->is_opened($yesterday), 1, "Cannot edit dates in the past without override : $yesterday is not a holiday");
79
80
$calendar->edit_holiday({
81
    title => "Single holiday Today",
82
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
83
    start_date => $yesterday,
84
    end_date => $yesterday,
85
    override => 1
86
});
87
is($calendar->is_opened($yesterday), 0, "Can edit dates in the past without override : $yesterday is a holiday");
88
89
90
my $days_between_start = DateTime->today;
91
my $days_between_end = DateTime->today->add(days => 6);
92
my $days_between = $calendar->days_between($days_between_start, $days_between_end)->in_units('days');
93
is($days_between, 5, "Days between skips holiday");
94
95
my $repeatable_holiday = DateTime->today->add(days => 1);
96
$calendar->edit_holiday({
97
    title => "repeatable",
98
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
99
    start_date=>$repeatable_holiday,
100
    end_date=>$repeatable_holiday
101
});
102
is($calendar->is_opened($repeatable_holiday), 0, "Branch not opened on $repeatable_holiday");
103
104
my @repeatable_holidays = $calendar->get_repeatable_holidays();
105
is(scalar @repeatable_holidays, 1, "Set of repeatable holidays at 1");
106
107
# 1 being mysql DAYOFWEEK() for Sunday
108
$calendar->edit_holiday({
109
    title => "Weekly",
110
    weekday=>1,
111
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
112
    start_date=>$today,
113
    end_date=>$today
114
});
115
my @weekly_holidays = $calendar->get_week_days_holidays();
116
is(scalar @weekly_holidays, 1, "Set of weekly holidays at 1");
117
118
my $sunday = DateTime->today->add(days =>( 7 - $today->day_of_week));
119
is($calendar->is_opened($sunday), 0, "Branch not opened on " . $sunday->day_name ."s");
120
121
my $unique_holiday_range_start = DateTime->today->add(days => 2);
122
my $unique_holiday_range_end = DateTime->today->add(days => 7);
123
$calendar->edit_holiday({
124
    title => "Single holiday range",
125
    holiday_type=>"E",
126
    start_date=>$unique_holiday_range_start,
127
    end_date=>$unique_holiday_range_end
128
});
129
@unique_holidays = $calendar->get_unique_holidays();
130
is(scalar @unique_holidays, 8, "Set of exception holidays at 7");
131
132
my $repeatable_holiday_range_start = DateTime->today->add(days => 8);
133
my $repeatable_holiday_range_end = DateTime->today->add(days => 13);
134
$calendar->edit_holiday({
135
    title => "Repeatable holiday range",
136
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
137
    start_date=>$repeatable_holiday_range_start,
138
    end_date=>$repeatable_holiday_range_end
139
});
140
@repeatable_holidays = $calendar->get_repeatable_holidays();
141
is(scalar @repeatable_holidays, 7, "Set of repeatable holidays at 7");
142
143
#Hourly loan
144
# ex :
145
# item due      : 2017-01-24 11:00:00
146
# item returned : 2017-01-26 10:00:00
147
# Branch closed : 2017-01-25
148
# Open/close hours : 08:00 to 16:00 (8h day)
149
# Hours due : 5 hours on 2017-01-24 + 2 hours on 2017-01-26 = 7hours
150
151
my $open_hours_since_start = dt_from_string->truncate(to => 'day')->add(days => 40, hours => 11);
152
my $open_hours_since_end = dt_from_string->truncate(to => 'day')->add(days => 42, hours => 10);
153
my $holiday_between =  dt_from_string->truncate(to => 'day')->add(days => 41);
154
$calendar->edit_holiday({
155
    title => '',
156
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
157
    start_date=>$open_hours_since_start,
158
    end_date=>$open_hours_since_end
159
});
160
161
$calendar->edit_holiday({
162
    title => "Single holiday",
163
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
164
    start_date=> $holiday_between,
165
    end_date=>$holiday_between
166
});
167
my $open_hours_between = $calendar->open_hours_between($open_hours_since_start, $open_hours_since_end);
168
is($open_hours_between, 7, "7 Hours open between $open_hours_since_start and $open_hours_since_end");
169
170
my $christmas = DateTime->new(
171
    year  => $today->year(),
172
    month => 12,
173
    day   => 25,
174
);
175
$calendar->edit_holiday({
176
    title => "Christmas",
177
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
178
    start_date=>$christmas,
179
    end_date=>$christmas,
180
    override => 1, # necessary if unit tests are run between Christmas and the first of the year
181
});
182
is($calendar->is_opened($christmas), 0, "Branch closed on Christmas : $christmas");
183
184
my $newyear = DateTime->new(
185
    year  => $today->year() +1,
186
    month => 1,
187
    day   => 1,
188
);
189
190
$calendar->edit_holiday({
191
    title => "New Year",
192
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
193
    start_date=>$newyear,
194
    end_date=>$newyear
195
});
196
is($calendar->is_opened($newyear), 0, "Branch closed on New Year : $newyear");
197
198
#Hours between :
199
my $date_due = DateTime->today->add(days =>1);
200
my $date_returned = DateTime->today->add(hours => 8);
201
my $hours_between = $calendar->hours_between($date_due, $date_returned);
202
203
is($hours_between->in_units('hours'), 16, "Date due $date_due, returned $date_returned, 16 hours in advance");
204
205
$date_due = DateTime->today->add(days =>1);
206
$date_returned = DateTime->today->add(days => 2, hours=> 8);
207
$hours_between = $calendar->hours_between($date_due, $date_returned);
208
209
is($hours_between->in_units('hours'), -16, "Date due $date_due, returned $date_returned, 16 hours late");
210
211
212
#delete holidays
213
is($calendar->is_opened($today), 0, "Today is closed");
214
$calendar->edit_holiday({
215
    title => '',
216
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
217
    start_date=>$unique_holiday,
218
    end_date=>$unique_holiday
219
});
220
is($calendar->is_opened($today), 1, "Today's holiday was removed");
221
222
$calendar->edit_holiday({
223
    title => '',
224
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
225
    start_date => $yesterday,
226
    end_date => $yesterday,
227
    override => 1
228
});
229
is($calendar->is_opened($yesterday), 1, "Yesterdays's holiday was removed with override");
230
231
my $new_open_hours = '08:00';
232
$calendar->edit_holiday({
233
    title => '',
234
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
235
    open_hour=>$new_open_hours,
236
    close_hour=>'',
237
    start_date=>$today,
238
    end_date=>$today
239
});
240
is($calendar->get_date_info($today, $branch1)->{open_hour}, '08:00:00', "Open hour changed to 08:00:00");
241
242
isnt($calendar->get_date_info($today, $branch1)->{close_hour}, '', "Close hour not removed");
243
244
my $delete_range_end = DateTime->today->add(days => 30);
245
$calendar->edit_holiday({
246
    title => '',
247
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
248
    start_date=>$today,
249
    end_date=>$delete_range_end
250
});
251
252
253
is($calendar->is_opened($today), 1, "Today's holiday was already removed");
254
is($calendar->is_opened(DateTime->today->add(days => 1)), 1, "Tomorrow's holiday was removed");
255
is($calendar->is_opened($delete_range_end), 1, "End of range holiday was removed");
256
257
#Check if other branch was affected
258
my @unique_holidays_branch2 = $calendar2->get_unique_holidays();
259
is(scalar @unique_holidays_branch2, 0, "Set of exception holidays at 0 for branch => $branch2");
260
my @repeatable_holidays_branch2 = $calendar2->get_repeatable_holidays();
261
is(scalar @repeatable_holidays_branch2, 0, "Set of repeatable holidays at 0 for branch => $branch2");
262
my @weekly_holidays_branch2 = $calendar2->get_week_days_holidays();
263
is(scalar @weekly_holidays_branch2, 0, "Set of weekly holidays at 0 for branch => $branch2");
264
265
266
#Tests for addDate()
267
268
my $one_day_dur = DateTime::Duration->new( days => 1 );
269
my $negative_one_day_dur = DateTime::Duration->new( days => - 1 );
270
my $two_day_dur = DateTime::Duration->new( days => 2 );
271
my $seven_day_dur = DateTime::Duration->new( days => 7 );
272
273
#Preference useDaysMode Calendar
274
$calendar->{days_mode} = 'Calendar';
275
$unique_holiday->add(days => 1);
276
my $tomorrow = DateTime->today->add(days => 1);
277
$calendar->edit_holiday({
278
    title => "Single holiday Today",
279
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
280
    start_date=>$tomorrow,
281
    end_date=>$tomorrow
282
});
283
284
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
285
    $today->add(days => 2)->ymd(),
286
    'Single day add (Calendar)' );
287
288
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
289
    $today->add(days => 2)->ymd(),
290
    'Two days add, skips holiday (Calendar)' );
291
292
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
293
    $today->add(days => 7)->ymd(),
294
    'Add 7 days (Calendar)' );
295
#Closed Sunday
296
$calendar->edit_holiday({
297
    title => "Weekly",
298
    weekday=>1,
299
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
300
    start_date=>$today,
301
    end_date=>$today
302
});
303
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
304
    'addDate skips closed Sunday (Calendar)' );
305
#to remove the closed sundays
306
$today = DateTime->today;
307
$calendar->edit_holiday({
308
    title => '',
309
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
310
    start_date=>$today,
311
    end_date=>$delete_range_end
312
});
313
314
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
315
    $today->add(days => - 1)->ymd(),
316
    'Negative call to addDate (Calendar)' );
317
318
#Preference useDaysMode DateDue
319
$calendar->{days_mode} = 'Datedue';
320
#clean everything
321
$today = DateTime->today;
322
$calendar->edit_holiday({
323
    title => '',
324
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
325
    start_date=>$today,
326
    end_date=>$delete_range_end
327
});
328
$calendar->edit_holiday({
329
    title => "Single holiday Today",
330
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
331
    start_date=>$tomorrow,
332
    end_date=>$tomorrow
333
});
334
335
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
336
    $today->add(days => 2)->ymd(),
337
    'Single day add' );
338
339
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
340
    $today->add(days => 2)->ymd(),
341
    'Two days add, skips holiday (Datedue)' );
342
343
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
344
    $today->add(days => 7)->ymd(),
345
    'Add 7 days (Datedue)' );
346
#Closed Sunday
347
$calendar->edit_holiday({
348
    title => "Weekly",
349
    weekday=>1,
350
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
351
    start_date=>$today,
352
    end_date=>$today
353
});
354
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
355
    'addDate skips closed Sunday (Datedue)' );
356
#to remove the closed sundays
357
$today = DateTime->today;
358
$calendar->edit_holiday({
359
    title => '',
360
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
361
    start_date=>$today,
362
    end_date=>$delete_range_end
363
});
364
365
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
366
    $today->add(days => - 1)->ymd(),
367
    'Negative call to addDate (Datedue)' );
368
369
#Preference useDaysMode Days
370
$calendar->{days_mode} = 'Days';
371
#clean everything
372
$today = DateTime->today;
373
$calendar->edit_holiday({
374
    title => '',
375
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
376
    start_date=>$today,
377
    end_date=>$delete_range_end
378
});
379
$calendar->edit_holiday({
380
    title => "Single holiday Today",
381
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
382
    start_date=>$tomorrow,
383
    end_date=>$tomorrow
384
});
385
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
386
    $today->add(days => 1)->ymd(),
387
    'Single day add' );
388
389
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
390
    $today->add(days => 2)->ymd(),
391
    'Two days add, skips holiday (Days)' );
392
393
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
394
    $today->add(days => 7)->ymd(),
395
    'Add 7 days (Days)' );
396
#Closed Sunday
397
$calendar->edit_holiday({
398
    title => "Weekly",
399
    weekday => 1,
400
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
401
    start_date => $today,
402
    end_date => $today
403
});
404
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
405
    'addDate skips closed Sunday (Days)' );
406
407
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
408
    $today->add(days => - 1)->ymd(),
409
    'Negative call to addDate (Days)' );
410
411
#Days_forward
412
413
#clean the range
414
$today = DateTime->today;
415
$calendar->edit_holiday({
416
    title => '',
417
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
418
    start_date => $today,
419
    end_date => DateTime->today->add(days => 20)
420
});
421
my $forwarded_dt = $calendar->days_forward($today, 10);
422
423
my $expected = $today->clone;
424
$expected->add(days => 10);
425
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days');
426
427
#Added a holiday
428
$unique_holiday = DateTime->today->add(days => 15);
429
$calendar->edit_holiday({
430
    title => "Single holiday Today",
431
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
432
    start_date => $unique_holiday,
433
    end_date => $unique_holiday
434
});
435
$forwarded_dt = $calendar->days_forward($today, 20);
436
437
$expected->add(days => 11);
438
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday');
439
440
$forwarded_dt = $calendar->days_forward($today, 0);
441
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
442
443
$forwarded_dt = $calendar->days_forward($today, -2);
444
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
445
446
#copying a branch to an other
447
is($calendar2->is_opened($tomorrow), 1, "$branch2 opened tomorrow");
448
#Added a goliday tomorrow for branch1
449
$calendar->edit_holiday({
450
    title => "Single holiday Today",
451
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
452
    start_date => $tomorrow,
453
    end_date => $tomorrow
454
});
455
#Copy dates from branch1 to branch2
456
$calendar->copy_to_branch($branch2);
457
#Check if branch2 is also closed tomorrow after copying from branch1
458
is($calendar2->is_opened($tomorrow), 0, "$branch2 close tomorrow after copying from $branch1");
459
460
$schema->storage->txn_rollback;
461
462
1;
(-)a/t/db_dependent/Fines.t (-5 / +6 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use DateTime;
4
5
5
use C4::Context;
6
use C4::Context;
6
use C4::Overdues;
7
use C4::Overdues;
Lines 31-53 my $issuingrule = $schema->resultset('Issuingrule')->create( Link Here
31
32
32
ok( $issuingrule, 'Issuing rule created' );
33
ok( $issuingrule, 'Issuing rule created' );
33
34
34
my $period_start = dt_from_string('2000-01-01');
35
my $period_start = dt_from_string;
35
my $period_end = dt_from_string('2000-01-05');
36
my $period_end = dt_from_string->add(days => 4);
36
37
37
my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
38
my ( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
38
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
39
is( $fine, 0, '4 days overdue, charge period 7 days, charge at end of interval gives fine of $0' );
39
40
40
$period_end = dt_from_string('2000-01-10');
41
$period_end = dt_from_string->add(days => 9);
41
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
42
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
42
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
43
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
43
44
44
# Test charging fine at the *beginning* of each charge period
45
# Test charging fine at the *beginning* of each charge period
45
$issuingrule->update( { chargeperiod_charge_at => 1 } );
46
$issuingrule->update( { chargeperiod_charge_at => 1 } );
46
47
47
$period_end = dt_from_string('2000-01-05');
48
$period_end = dt_from_string->add(days => 4);
48
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
49
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
49
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
50
is( $fine, 1, '4 days overdue, charge period 7 days, charge at start of interval gives fine of $1' );
50
51
51
$period_end = dt_from_string('2000-01-10');
52
$period_end = dt_from_string->add(days => 9);
52
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
53
( $fine ) = CalcFine( {}, q{}, q{}, $period_start, $period_end  );
53
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );
54
is( $fine, 2, '9 days overdue, charge period 7 days, charge at start of interval gives fine of $2' );
(-)a/t/db_dependent/Hold.t (-6 / +14 lines)
Lines 22-28 use C4::Context; Link Here
22
use C4::Biblio qw( AddBiblio );
22
use C4::Biblio qw( AddBiblio );
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Libraries;
24
use Koha::Libraries;
25
use C4::Calendar;
25
use Koha::DiscreteCalendar;
26
use Koha::Patrons;
26
use Koha::Patrons;
27
use Koha::Holds;
27
use Koha::Holds;
28
use Koha::Item;
28
use Koha::Item;
Lines 68-74 my $hold = Koha::Hold->new( Link Here
68
    {
68
    {
69
        biblionumber   => $biblionumber,
69
        biblionumber   => $biblionumber,
70
        itemnumber     => $item->id(),
70
        itemnumber     => $item->id(),
71
        reservedate    => '2017-01-01',
71
        reservedate    => dt_from_string->subtract(days => 2),
72
        waitingdate    => '2000-01-01',
72
        waitingdate    => '2000-01-01',
73
        borrowernumber => $borrower->{borrowernumber},
73
        borrowernumber => $borrower->{borrowernumber},
74
        branchcode     => $branches[1]->{branchcode},
74
        branchcode     => $branches[1]->{branchcode},
Lines 77-87 my $hold = Koha::Hold->new( Link Here
77
);
77
);
78
$hold->store();
78
$hold->store();
79
79
80
my $b1_cal = C4::Calendar->new( branchcode => $branches[1]->{branchcode} );
80
my $b1_cal = Koha::DiscreteCalendar->new({ branchcode => $branches[1]->{branchcode} });
81
$b1_cal->insert_single_holiday( day => 02, month => 01, year => 2017, title => "Morty Day", description => "Rick" ); #Add a holiday
81
my $holiday = dt_from_string->subtract(days => 1);
82
$b1_cal->edit_holiday({
83
    title => "Morty Day",
84
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
85
    start_date => $holiday,
86
    end_date => $holiday,
87
    override => 1
88
}); #Add a holiday
89
82
my $today = dt_from_string;
90
my $today = dt_from_string;
83
is( $hold->age(), $today->delta_days( dt_from_string( '2017-01-01' ) )->in_units( 'days')  , "Age of hold is days from reservedate to now if calendar ignored");
91
is( $hold->age(), $today->delta_days( dt_from_string->subtract(days => 2) )->in_units( 'days' ), "Age of hold is days from reservedate to now if calendar ignored");
84
is( $hold->age(1), $today->delta_days( dt_from_string( '2017-01-01' ) )->in_units( 'days' ) - 1 , "Age of hold is days from reservedate to now minus 1 if calendar used");
92
is( $hold->age(1), $today->delta_days( dt_from_string->subtract(days => 2) )->in_units( 'days' ) - 1, "Age of hold is days from reservedate to now minus 1 if calendar used");
85
93
86
is( $hold->suspend, 0, "Hold is not suspended" );
94
is( $hold->suspend, 0, "Hold is not suspended" );
87
$hold->suspend_hold();
95
$hold->suspend_hold();
(-)a/t/db_dependent/HoldsQueue.t (-9 / +25 lines)
Lines 11-19 use Modern::Perl; Link Here
11
use Test::More tests => 48;
11
use Test::More tests => 48;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Calendar;
15
use C4::Context;
14
use C4::Context;
16
use C4::Members;
15
use C4::Members;
16
use Koha::DiscreteCalendar;
17
use Koha::Database;
17
use Koha::Database;
18
use Koha::DateUtils;
18
use Koha::DateUtils;
19
use Koha::Items;
19
use Koha::Items;
Lines 192-197 $library2 = $builder->build({ Link Here
192
$library3 = $builder->build({
192
$library3 = $builder->build({
193
    source => 'Branch',
193
    source => 'Branch',
194
});
194
});
195
196
$schema->resultset('DiscreteCalendar')->search({
197
    branchcode  =>''
198
})->update_all({
199
    is_opened    => 1,
200
    holiday_type => '',
201
    note        => '',
202
    open_hour    => '08:00:00',
203
    close_hour   => '16:00:00'
204
});
205
206
Koha::DiscreteCalendar->new({ branchcode => '' })->add_new_branch('', $library1->{branchcode});
207
Koha::DiscreteCalendar->new({ branchcode => '' })->add_new_branch('', $library2->{branchcode});
208
Koha::DiscreteCalendar->new({ branchcode => '' })->add_new_branch('', $library3->{branchcode});
209
195
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
210
@branchcodes = ( $library1->{branchcode}, $library2->{branchcode}, $library3->{branchcode} );
196
211
197
my $borrower1 = $builder->build({
212
my $borrower1 = $builder->build({
Lines 313-328 is( $holds_queue->[1]->{cardnumber}, $borrower2->{cardnumber}, "Holds queue fill Link Here
313
# have 1 row in the holds queue
328
# have 1 row in the holds queue
314
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1);
329
t::lib::Mocks::mock_preference('HoldsQueueSkipClosed', 1);
315
my $today = dt_from_string();
330
my $today = dt_from_string();
316
C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday(
331
317
    day         => $today->day(),
318
    month       => $today->month(),
319
    year        => $today->year(),
320
    title       => "$today",
321
    description => "$today",
322
);
323
# If the test below is removed, aother tests using the holiday will fail. For some reason if we call is_holiday now
332
# If the test below is removed, aother tests using the holiday will fail. For some reason if we call is_holiday now
324
# the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead.
333
# the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead.
325
is( Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' );
334
Koha::DiscreteCalendar->new({ branchcode => $branchcodes[0] })->edit_holiday({
335
    title        => "Today",
336
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
337
    start_date   => $today,
338
    end_date     => $today
339
});
340
341
is( Koha::DiscreteCalendar->new({ branchcode => $branchcodes[0] })->is_holiday( $today ), 1, 'Is today a holiday for pickup branch' );
326
C4::HoldsQueue::CreateQueue();
342
C4::HoldsQueue::CreateQueue();
327
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
343
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
328
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
344
is( scalar( @$holds_queue ), 1, "Holds not filled with items from closed libraries" );
(-)a/t/db_dependent/Holidays.t (-205 lines)
Lines 1-205 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 16;
21
22
use DateTime;
23
use DateTime::TimeZone;
24
25
use t::lib::TestBuilder;
26
use C4::Context;
27
use Koha::Database;
28
use Koha::DateUtils;
29
30
31
BEGIN {
32
    use_ok('Koha::Calendar');
33
    use_ok('C4::Calendar');
34
}
35
36
my $schema = Koha::Database->new->schema;
37
my $dbh = C4::Context->dbh;
38
my $builder = t::lib::TestBuilder->new;
39
40
subtest 'exception_holidays() tests' => sub {
41
42
    plan tests => 1;
43
44
    $schema->storage->txn_begin;
45
46
    $dbh->do("DELETE FROM special_holidays");
47
    # Clear cache
48
    Koha::Caches->get_instance->flush_all;
49
50
    # Artificially set timezone
51
    my $timezone = 'America/Santiago';
52
    $ENV{TZ} = $timezone;
53
    use POSIX qw(tzset);
54
    tzset;
55
56
    my $branch = $builder->build( { source => 'Branch' } )->{branchcode};
57
    my $calendar = Koha::Calendar->new( branchcode => $branch );
58
59
    C4::Calendar->new( branchcode => $branch )->insert_exception_holiday(
60
        day         => 6,
61
        month       => 9,
62
        year        => 2015,
63
        title       => 'Invalid date',
64
        description => 'Invalid date description',
65
    );
66
67
    my $exception_holiday = $calendar->exception_holidays->iterator->next;
68
    my $now_dt            = DateTime->now;
69
70
    my $diff;
71
    eval { $diff = $calendar->days_between( $now_dt, $exception_holiday ) };
72
    unlike(
73
        $@,
74
        qr/Invalid local time for date in time zone: America\/Santiago/,
75
        'Avoid invalid datetime due to DST'
76
    );
77
78
    $schema->storage->txn_rollback;
79
};
80
81
$schema->storage->txn_begin;
82
83
# Create two fresh branches for the tests
84
my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
85
my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode };
86
87
C4::Calendar->new( branchcode => $branch_1 )->insert_week_day_holiday(
88
    weekday     => 0,
89
    title       => '',
90
    description => 'Sundays',
91
);
92
93
my $holiday2add = dt_from_string("2015-01-01");
94
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
95
    day         => $holiday2add->day(),
96
    month       => $holiday2add->month(),
97
    year        => $holiday2add->year(),
98
    title       => '',
99
    description => "New Year's Day",
100
);
101
$holiday2add = dt_from_string("2014-12-25");
102
C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday(
103
    day         => $holiday2add->day(),
104
    month       => $holiday2add->month(),
105
    year        => $holiday2add->year(),
106
    title       => '',
107
    description => 'Christmas',
108
);
109
110
my $koha_calendar = Koha::Calendar->new( branchcode => $branch_1 );
111
my $c4_calendar = C4::Calendar->new( branchcode => $branch_1 );
112
113
isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' );
114
isa_ok( $c4_calendar,   'C4::Calendar',   'C4::Calendar class returned' );
115
116
my $sunday = DateTime->new(
117
    year  => 2011,
118
    month => 6,
119
    day   => 26,
120
);
121
my $monday = DateTime->new(
122
    year  => 2011,
123
    month => 6,
124
    day   => 27,
125
);
126
my $christmas = DateTime->new(
127
    year  => 2032,
128
    month => 12,
129
    day   => 25,
130
);
131
my $newyear = DateTime->new(
132
    year  => 2035,
133
    month => 1,
134
    day   => 1,
135
);
136
137
is( $koha_calendar->is_holiday($sunday),    1, 'Sunday is a closed day' );
138
is( $koha_calendar->is_holiday($monday),    0, 'Monday is not a closed day' );
139
is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' );
140
is( $koha_calendar->is_holiday($newyear),   1, 'New Years day is a closed day' );
141
142
$dbh->do("DELETE FROM repeatable_holidays");
143
$dbh->do("DELETE FROM special_holidays");
144
145
my $custom_holiday = DateTime->new(
146
    year  => 2013,
147
    month => 11,
148
    day   => 12,
149
);
150
151
my $today = dt_from_string();
152
C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday(
153
    day         => $today->day(),
154
    month       => $today->month(),
155
    year        => $today->year(),
156
    title       => "$today",
157
    description => "$today",
158
);
159
160
is( Koha::Calendar->new( branchcode => $branch_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" );
161
is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1");
162
163
# Few tests for exception holidays
164
my ( $diff, $cal, $special );
165
$dbh->do("DELETE FROM special_holidays");
166
_add_exception( $today, $branch_1, 'Today' );
167
$cal = Koha::Calendar->new( branchcode => $branch_1 );
168
$special = $cal->exception_holidays;
169
is( $special->count, 1, 'One exception holiday added' );
170
171
my $tomorrow= dt_from_string();
172
$tomorrow->add_duration( DateTime::Duration->new(days => 1) );
173
_add_exception( $tomorrow, $branch_1, 'Tomorrow' );
174
$cal = Koha::Calendar->new( branchcode => $branch_1 );
175
$special = $cal->exception_holidays;
176
is( $special->count, 2, 'Set of exception holidays contains two dates' );
177
178
$diff = $today->delta_days( $special->min )->in_units('days');
179
is( $diff, 0, 'Lowest exception holiday is today' );
180
$diff = $tomorrow->delta_days( $special->max )->in_units('days');
181
is( $diff, 0, 'Highest exception holiday is tomorrow' );
182
183
C4::Calendar->new( branchcode => $branch_1 )->delete_holiday(
184
    weekday => $tomorrow->day_of_week,
185
    day     => $tomorrow->day,
186
    month   => $tomorrow->month,
187
    year    => $tomorrow->year,
188
);
189
$cal = Koha::Calendar->new( branchcode => $branch_1 );
190
$special = $cal->exception_holidays;
191
is( $special->count, 1, 'Set of exception holidays back to one' );
192
193
sub _add_exception {
194
    my ( $dt, $branch, $descr ) = @_;
195
    C4::Calendar->new( branchcode => $branch )->insert_exception_holiday(
196
        day         => $dt->day,
197
        month       => $dt->month,
198
        year        => $dt->year,
199
        title       => $descr,
200
        description => $descr,
201
    );
202
}
203
204
$schema->storage->txn_rollback;
205
(-)a/t/lib/TestBuilder.pm (-1 / +6 lines)
Lines 437-442 sub _gen_type { Link Here
437
        decimal          => \&_gen_real,
437
        decimal          => \&_gen_real,
438
        double_precision => \&_gen_real,
438
        double_precision => \&_gen_real,
439
439
440
        time      => \&_gen_time,
440
        timestamp => \&_gen_datetime,
441
        timestamp => \&_gen_datetime,
441
        datetime  => \&_gen_datetime,
442
        datetime  => \&_gen_datetime,
442
        date      => \&_gen_date,
443
        date      => \&_gen_date,
Lines 500-505 sub _gen_datetime { Link Here
500
    return $self->schema->storage->datetime_parser->format_datetime(dt_from_string);
501
    return $self->schema->storage->datetime_parser->format_datetime(dt_from_string);
501
}
502
}
502
503
504
sub _gen_time {
505
    my ($self, $params) = @_;
506
    return $self->schema->storage->datetime_parser->format_time(DateTime->now());
507
}
508
503
sub _gen_text {
509
sub _gen_text {
504
    my ($self, $params) = @_;
510
    my ($self, $params) = @_;
505
    # From perldoc String::Random
511
    # From perldoc String::Random
506
- 

Return to bug 17015