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

(-)a/C4/Overdues.pm (-1 lines)
Lines 30-36 use Carp qw( carp ); Link Here
30
use C4::Accounts;
30
use C4::Accounts;
31
use C4::Context;
31
use C4::Context;
32
use C4::Log; # logaction
32
use C4::Log; # logaction
33
use C4::Debug;
34
use Koha::DateUtils;
33
use Koha::DateUtils;
35
use Koha::DiscreteCalendar;
34
use Koha::DiscreteCalendar;
36
use Koha::Account::Lines;
35
use Koha::Account::Lines;
(-)a/Koha/DiscreteCalendar.pm (-3 / +2 lines)
Lines 27-33 use Data::Dumper; Link Here
27
use C4::Context;
27
use C4::Context;
28
use C4::Output;
28
use C4::Output;
29
use Koha::Database;
29
use Koha::Database;
30
use Koha::DateUtils;
30
use Koha::DateUtils qw ( dt_from_string output_pref );
31
31
32
# Global variables to make code more readable
32
# Global variables to make code more readable
33
our $HOLIDAYS = {
33
our $HOLIDAYS = {
Lines 502-510 sub get_week_days_holidays { Link Here
502
            branchcode   => $branchcode,
502
            branchcode   => $branchcode,
503
        },
503
        },
504
        {
504
        {
505
            select   => [{ DAYOFWEEK => 'date'}, 'note'],
505
            select   => \[ 'distinct DAYOFWEEK(date), note'],
506
            as       => [qw/ weekday note /],
506
            as       => [qw/ weekday note /],
507
            distinct => 1,
508
            where    => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ),
507
            where    => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ),
509
        }
508
        }
510
    );
509
    );
(-)a/misc/cronjobs/add_days_discrete_calendar.pl (-2 / +2 lines)
Lines 11-17 use Getopt::Long; Link Here
11
use C4::Context;
11
use C4::Context;
12
use Koha::Database;
12
use Koha::Database;
13
use Koha::DiscreteCalendar;
13
use Koha::DiscreteCalendar;
14
use Koha::DateUtils;
14
use Koha::DateUtils qw ( output_pref );
15
15
16
# Options
16
# Options
17
my $help = 0;
17
my $help = 0;
Lines 162-165 foreach my $branchCode (@branches) { Link Here
162
    }
162
    }
163
}
163
}
164
# If everything went well we commit to the database
164
# If everything went well we commit to the database
165
$schema->storage->txn_commit;
165
$schema->storage->txn_commit;
(-)a/misc/cronjobs/holds/holds_reminder.pl (-2 / +2 lines)
Lines 26-32 use C4::Context; Link Here
26
use C4::Letters;
26
use C4::Letters;
27
use C4::Log qw( cronlogaction );
27
use C4::Log qw( cronlogaction );
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
29
use Koha::Calendar;
29
use Koha::DiscreteCalendar;
30
use Koha::Libraries;
30
use Koha::Libraries;
31
use Koha::Notice::Templates;
31
use Koha::Notice::Templates;
32
use Koha::Patrons;
32
use Koha::Patrons;
Lines 246-252 foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP Link Here
246
    # If respecting calendar get the correct waiting since date
246
    # If respecting calendar get the correct waiting since date
247
    my $waiting_date;
247
    my $waiting_date;
248
    if( $use_calendar ){
248
    if( $use_calendar ){
249
        my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' );
249
        my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode, days_mode => 'Calendar' );
250
        my $duration = DateTime::Duration->new( days => -$days );
250
        my $duration = DateTime::Duration->new( days => -$days );
251
        $waiting_date = $calendar->addDays($date_to_run,$duration); #Add negative of days
251
        $waiting_date = $calendar->addDays($date_to_run,$duration); #Add negative of days
252
    } else {
252
    } else {
(-)a/misc/cronjobs/staticfines.pl (-1 lines)
Lines 39-45 use Koha::DateUtils qw( dt_from_string output_pref ); Link Here
39
use C4::Circulation;
39
use C4::Circulation;
40
use Koha::DiscreteCalendar qw();    # don't need any exports from Calendar
40
use Koha::DiscreteCalendar qw();    # don't need any exports from Calendar
41
use C4::Biblio;
41
use C4::Biblio;
42
use C4::Debug;            # supplying $debug and $cgi_debug
43
use Koha::Patrons;
42
use Koha::Patrons;
44
43
45
my $help    = 0;
44
my $help    = 0;
(-)a/t/db_dependent/DiscreteCalendar.t (-17 / +17 lines)
Lines 23-29 use Test::MockModule; Link Here
23
23
24
use C4::Context;
24
use C4::Context;
25
use C4::Output;
25
use C4::Output;
26
use Koha::DateUtils;
26
use Koha::DateUtils qw ( dt_from_string );
27
use Koha::DiscreteCalendar;
27
use Koha::DiscreteCalendar;
28
28
29
29
Lines 127-133 $calendar->edit_holiday({ Link Here
127
    end_date=>$unique_holiday_range_end
127
    end_date=>$unique_holiday_range_end
128
});
128
});
129
@unique_holidays = $calendar->get_unique_holidays();
129
@unique_holidays = $calendar->get_unique_holidays();
130
is(scalar @unique_holidays, 8, "Set of exception holidays at 7");
130
is(scalar @unique_holidays, 7, "Set of exception holidays at 7");
131
131
132
my $repeatable_holiday_range_start = DateTime->today->add(days => 8);
132
my $repeatable_holiday_range_start = DateTime->today->add(days => 8);
133
my $repeatable_holiday_range_end = DateTime->today->add(days => 13);
133
my $repeatable_holiday_range_end = DateTime->today->add(days => 13);
Lines 281-295 $calendar->edit_holiday({ Link Here
281
    end_date=>$tomorrow
281
    end_date=>$tomorrow
282
});
282
});
283
283
284
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
284
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
285
    $today->add(days => 2)->ymd(),
285
    $today->add(days => 2)->ymd(),
286
    'Single day add (Calendar)' );
286
    'Single day add (Calendar)' );
287
287
288
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
288
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
289
    $today->add(days => 2)->ymd(),
289
    $today->add(days => 2)->ymd(),
290
    'Two days add, skips holiday (Calendar)' );
290
    'Two days add, skips holiday (Calendar)' );
291
291
292
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
292
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
293
    $today->add(days => 7)->ymd(),
293
    $today->add(days => 7)->ymd(),
294
    'Add 7 days (Calendar)' );
294
    'Add 7 days (Calendar)' );
295
#Closed Sunday
295
#Closed Sunday
Lines 300-306 $calendar->edit_holiday({ Link Here
300
    start_date=>$today,
300
    start_date=>$today,
301
    end_date=>$today
301
    end_date=>$today
302
});
302
});
303
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
303
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
304
    'addDate skips closed Sunday (Calendar)' );
304
    'addDate skips closed Sunday (Calendar)' );
305
#to remove the closed sundays
305
#to remove the closed sundays
306
$today = DateTime->today;
306
$today = DateTime->today;
Lines 311-317 $calendar->edit_holiday({ Link Here
311
    end_date=>$delete_range_end
311
    end_date=>$delete_range_end
312
});
312
});
313
313
314
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
314
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
315
    $today->add(days => - 1)->ymd(),
315
    $today->add(days => - 1)->ymd(),
316
    'Negative call to addDate (Calendar)' );
316
    'Negative call to addDate (Calendar)' );
317
317
Lines 332-346 $calendar->edit_holiday({ Link Here
332
    end_date=>$tomorrow
332
    end_date=>$tomorrow
333
});
333
});
334
334
335
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
335
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
336
    $today->add(days => 2)->ymd(),
336
    $today->add(days => 2)->ymd(),
337
    'Single day add' );
337
    'Single day add' );
338
338
339
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
339
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
340
    $today->add(days => 2)->ymd(),
340
    $today->add(days => 2)->ymd(),
341
    'Two days add, skips holiday (Datedue)' );
341
    'Two days add, skips holiday (Datedue)' );
342
342
343
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
343
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
344
    $today->add(days => 7)->ymd(),
344
    $today->add(days => 7)->ymd(),
345
    'Add 7 days (Datedue)' );
345
    'Add 7 days (Datedue)' );
346
#Closed Sunday
346
#Closed Sunday
Lines 351-357 $calendar->edit_holiday({ Link Here
351
    start_date=>$today,
351
    start_date=>$today,
352
    end_date=>$today
352
    end_date=>$today
353
});
353
});
354
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
354
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
355
    'addDate skips closed Sunday (Datedue)' );
355
    'addDate skips closed Sunday (Datedue)' );
356
#to remove the closed sundays
356
#to remove the closed sundays
357
$today = DateTime->today;
357
$today = DateTime->today;
Lines 362-368 $calendar->edit_holiday({ Link Here
362
    end_date=>$delete_range_end
362
    end_date=>$delete_range_end
363
});
363
});
364
364
365
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
365
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
366
    $today->add(days => - 1)->ymd(),
366
    $today->add(days => - 1)->ymd(),
367
    'Negative call to addDate (Datedue)' );
367
    'Negative call to addDate (Datedue)' );
368
368
Lines 382-396 $calendar->edit_holiday({ Link Here
382
    start_date=>$tomorrow,
382
    start_date=>$tomorrow,
383
    end_date=>$tomorrow
383
    end_date=>$tomorrow
384
});
384
});
385
is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(),
385
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
386
    $today->add(days => 1)->ymd(),
386
    $today->add(days => 1)->ymd(),
387
    'Single day add' );
387
    'Single day add' );
388
388
389
is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(),
389
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
390
    $today->add(days => 2)->ymd(),
390
    $today->add(days => 2)->ymd(),
391
    'Two days add, skips holiday (Days)' );
391
    'Two days add, skips holiday (Days)' );
392
392
393
cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
393
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
394
    $today->add(days => 7)->ymd(),
394
    $today->add(days => 7)->ymd(),
395
    'Add 7 days (Days)' );
395
    'Add 7 days (Days)' );
396
#Closed Sunday
396
#Closed Sunday
Lines 401-410 $calendar->edit_holiday({ Link Here
401
    start_date => $today,
401
    start_date => $today,
402
    end_date => $today
402
    end_date => $today
403
});
403
});
404
is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
404
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
405
    'addDate skips closed Sunday (Days)' );
405
    'addDate skips closed Sunday (Days)' );
406
406
407
is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(),
407
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
408
    $today->add(days => - 1)->ymd(),
408
    $today->add(days => - 1)->ymd(),
409
    'Negative call to addDate (Days)' );
409
    'Negative call to addDate (Days)' );
410
410
(-)a/tools/discrete_calendar.pl (-4 / +3 lines)
Lines 20-29 use Modern::Perl; Link Here
20
20
21
use CGI qw ( -utf8 );
21
use CGI qw ( -utf8 );
22
22
23
use C4::Auth;
23
use C4::Auth qw ( get_template_and_user );
24
use C4::Output;
24
use C4::Output qw ( output_html_with_http_headers );
25
25
26
use Koha::DateUtils;
26
use Koha::DateUtils qw ( dt_from_string output_pref );
27
use Koha::DiscreteCalendar;
27
use Koha::DiscreteCalendar;
28
28
29
my $input = CGI->new;
29
my $input = CGI->new;
30
- 

Return to bug 17015