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

(-)a/C4/Calendar.pm (-7 / +49 lines)
Lines 23-30 use Carp; Link Here
23
use Date::Calc qw( Date_to_Days Today);
23
use Date::Calc qw( Date_to_Days Today);
24
24
25
use C4::Context;
25
use C4::Context;
26
use Koha::Cache;
26
27
27
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
28
use constant ISO_DATE_FORMAT => "%04d-%02d-%02d";
29
28
=head1 NAME
30
=head1 NAME
29
31
30
C4::Calendar::Calendar - Koha module dealing with holidays.
32
C4::Calendar::Calendar - Koha module dealing with holidays.
Lines 262-268 C<$description> Is the description to store for the holiday formed by $year/$mon Link Here
262
sub insert_single_holiday {
264
sub insert_single_holiday {
263
    my $self = shift @_;
265
    my $self = shift @_;
264
    my %options = @_;
266
    my %options = @_;
265
    
266
    @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o )
267
    @options{qw(year month day)} = ( $options{date} =~ m/(\d+)-(\d+)-(\d+)/o )
267
      if $options{date} && !$options{day};
268
      if $options{date} && !$options{day};
268
269
Lines 272-278 sub insert_single_holiday { Link Here
272
	$insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
273
	$insertHoliday->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
273
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
274
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
274
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
275
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
276
277
278
    # changed the 'single_holidays' table, lets force/reset its cache
279
    my $cache = Koha::Cache->get_instance();
280
    $cache->clear_from_cache( 'single_holidays') ;
281
275
    return $self;
282
    return $self;
283
276
}
284
}
277
285
278
=head2 insert_exception_holiday
286
=head2 insert_exception_holiday
Lines 310-315 sub insert_exception_holiday { Link Here
310
	$insertException->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
318
	$insertException->execute( $self->{branchcode}, $options{day},$options{month},$options{year}, $isexception, $options{title}, $options{description});
311
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
319
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
312
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
320
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
321
322
    # changed the 'single_holidays' table, lets force/reset its cache
323
    my $cache = Koha::Cache->get_instance();
324
    $cache->clear_from_cache( 'single_holidays') ;
325
313
    return $self;
326
    return $self;
314
}
327
}
315
328
Lines 398-407 sub ModSingleholiday { Link Here
398
411
399
    my $dbh = C4::Context->dbh();
412
    my $dbh = C4::Context->dbh();
400
    my $isexception = 0;
413
    my $isexception = 0;
401
    my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
414
415
    my $updateHoliday = $dbh->prepare("
416
UPDATE special_holidays SET title = ?, description = ?
417
    WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
402
      $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);    
418
      $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);    
403
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
419
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
404
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
420
    $self->{'single_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
421
422
    # changed the 'single_holidays' table, lets force/reset its cache
423
    my $cache = Koha::Cache->get_instance();
424
    $cache->clear_from_cache( 'single_holidays') ;
425
405
    return $self;
426
    return $self;
406
}
427
}
407
428
Lines 433-442 sub ModExceptionholiday { Link Here
433
454
434
    my $dbh = C4::Context->dbh();
455
    my $dbh = C4::Context->dbh();
435
    my $isexception = 1;
456
    my $isexception = 1;
436
    my $updateHoliday = $dbh->prepare("UPDATE special_holidays SET title = ?, description = ? WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
457
    my $updateHoliday = $dbh->prepare("
437
    $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);    
458
UPDATE special_holidays SET title = ?, description = ?
459
    WHERE day = ? AND month = ? AND year = ? AND branchcode = ? AND isexception = ?");
460
    $updateHoliday->execute($options{title},$options{description},$options{day},$options{month},$options{year},$self->{branchcode},$isexception);
438
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
461
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{title} = $options{title};
439
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
462
    $self->{'exception_holidays'}->{"$options{year}/$options{month}/$options{day}"}{description} = $options{description};
463
464
    # changed the 'single_holidays' table, lets force/reset its cache
465
    my $cache = Koha::Cache->get_instance();
466
    $cache->clear_from_cache( 'single_holidays') ;
467
440
    return $self;
468
    return $self;
441
}
469
}
442
470
Lines 465-471 sub delete_holiday { Link Here
465
493
466
    # Verify what kind of holiday that day is. For example, if it is
494
    # Verify what kind of holiday that day is. For example, if it is
467
    # a repeatable holiday, this should check if there are some exception
495
    # a repeatable holiday, this should check if there are some exception
468
	# for that holiday rule. Otherwise, if it is a regular holiday, it´s 
496
    # for that holiday rule. Otherwise, if it is a regular holiday, it´s
469
    # ok just deleting it.
497
    # ok just deleting it.
470
498
471
    my $dbh = C4::Context->dbh();
499
    my $dbh = C4::Context->dbh();
Lines 512-517 sub delete_holiday { Link Here
512
            }
540
            }
513
        }
541
        }
514
    }
542
    }
543
544
    # changed the 'single_holidays' table, lets force/reset its cache
545
    my $cache = Koha::Cache->get_instance();
546
    $cache->clear_from_cache( 'single_holidays') ;
547
515
    return $self;
548
    return $self;
516
}
549
}
517
=head2 delete_holiday_range
550
=head2 delete_holiday_range
Lines 537-542 sub delete_holiday_range { Link Here
537
    my $dbh = C4::Context->dbh();
570
    my $dbh = C4::Context->dbh();
538
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
571
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (day = ?) AND (month = ?) AND (year = ?)");
539
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
572
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
573
574
    # changed the 'single_holidays' table, lets force/reset its cache
575
    my $cache = Koha::Cache->get_instance();
576
    $cache->clear_from_cache( 'single_holidays') ;
577
540
}
578
}
541
579
542
=head2 delete_holiday_range_repeatable
580
=head2 delete_holiday_range_repeatable
Lines 585-590 sub delete_exception_holiday_range { Link Here
585
    my $dbh = C4::Context->dbh();
623
    my $dbh = C4::Context->dbh();
586
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
624
    my $sth = $dbh->prepare("DELETE FROM special_holidays WHERE (branchcode = ?) AND (isexception = 1) AND (day = ?) AND (month = ?) AND (year = ?)");
587
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
625
    $sth->execute($self->{branchcode}, $options{day}, $options{month}, $options{year});
626
627
    # changed the 'single_holidays' table, lets force/reset its cache
628
    my $cache = Koha::Cache->get_instance();
629
    $cache->clear_from_cache( 'single_holidays') ;
588
}
630
}
589
631
590
=head2 isHoliday
632
=head2 isHoliday
Lines 606-612 sub isHoliday { Link Here
606
	$month=$month+0;
648
	$month=$month+0;
607
	$year=$year+0;
649
	$year=$year+0;
608
	$day=$day+0;
650
	$day=$day+0;
609
    my $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7; 
651
    my $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7;
610
    my $weekDays   = $self->get_week_days_holidays();
652
    my $weekDays   = $self->get_week_days_holidays();
611
    my $dayMonths  = $self->get_day_month_holidays();
653
    my $dayMonths  = $self->get_day_month_holidays();
612
    my $exceptions = $self->get_exception_holidays();
654
    my $exceptions = $self->get_exception_holidays();
Lines 617-623 sub isHoliday { Link Here
617
        if ((exists($weekDays->{$weekday})) ||
659
        if ((exists($weekDays->{$weekday})) ||
618
            (exists($dayMonths->{"$month/$day"})) ||
660
            (exists($dayMonths->{"$month/$day"})) ||
619
            (exists($singles->{"$year/$month/$day"}))) {
661
            (exists($singles->{"$year/$month/$day"}))) {
620
		 	return 1;
662
            return 1;
621
        } else {
663
        } else {
622
            return 0;
664
            return 0;
623
        }
665
        }
(-)a/Koha/Calendar.pm (-33 / +92 lines)
Lines 7-12 use DateTime; Link Here
7
use DateTime::Set;
7
use DateTime::Set;
8
use DateTime::Duration;
8
use DateTime::Duration;
9
use C4::Context;
9
use C4::Context;
10
use Koha::Cache;
10
use Carp;
11
use Carp;
11
12
12
sub new {
13
sub new {
Lines 57-63 sub _init { Link Here
57
# is allowing this with the expectation that prior to release of
58
# is allowing this with the expectation that prior to release of
58
# 3.16, bug 8089 will be fixed and we can switch the caching over
59
# 3.16, bug 8089 will be fixed and we can switch the caching over
59
# to Koha::Cache.
60
# to Koha::Cache.
60
our ( $exception_holidays, $single_holidays );
61
62
our ( $exception_holidays, $single_holidays ); ## no need for $single_holidays now, surely?
63
61
sub exception_holidays {
64
sub exception_holidays {
62
    my ( $self ) = @_;
65
    my ( $self ) = @_;
63
    my $dbh = C4::Context->dbh;
66
    my $dbh = C4::Context->dbh;
Lines 87-117 sub exception_holidays { Link Here
87
}
90
}
88
91
89
sub single_holidays {
92
sub single_holidays {
90
    my ( $self ) = @_;
93
    my ( $self, $date ) = @_;
91
    my $dbh = C4::Context->dbh;
92
    my $branchcode = $self->{branchcode};
94
    my $branchcode = $self->{branchcode};
93
    if ( $single_holidays->{$branchcode} ) {
95
    my $cache           = Koha::Cache->get_instance();
94
        $self->{single_holidays}{$branchcode} = $single_holidays->{$branchcode};
96
    my $single_holidays = $cache->get_from_cache('single_holidays');
95
        return $single_holidays->{$branchcode};
97
96
    }
98
=c
97
    my $single_holidays_sth = $dbh->prepare(
99
$single_holidays looks like this..
100
101
\ {
102
   CPL   [
103
        [0] 20131122,
104
        [1] 20131123,
105
        [2] 20131124
106
    ],
107
   MPL   [
108
        [0] 20131122,
109
        [1] 20131123,
110
        [2] 20131124
111
    ]
112
}
113
114
=cut
115
116
    unless ($single_holidays) {
117
        my $dbh = C4::Context->dbh;
118
        $single_holidays = {};
119
120
        # push holidays for each branch
121
        my $branches_sth =
122
          $dbh->prepare('SELECT distinct(branchcode) FROM special_holidays');
123
        $branches_sth->execute();
124
        while ( my $br = $branches_sth->fetchrow ) {
125
            my $single_holidays_sth = $dbh->prepare(
98
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
126
'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
99
    );
127
            );
100
    $single_holidays_sth->execute( $branchcode );
128
            $single_holidays_sth->execute($branchcode);
101
    my $dates = [];
129
102
    while ( my ( $day, $month, $year ) = $single_holidays_sth->fetchrow ) {
130
            my @ymd_arr;
103
        push @{$dates},
131
            while ( my ( $day, $month, $year ) =
104
          DateTime->new(
132
                $single_holidays_sth->fetchrow )
105
            day       => $day,
133
            {
106
            month     => $month,
134
                my $dt = DateTime->new(
107
            year      => $year,
135
                    day       => $day,
108
            time_zone => C4::Context->tz()
136
                    month     => $month,
109
          )->truncate( to => 'day' );
137
                    year      => $year,
138
                    time_zone => C4::Context->tz()
139
                )->truncate( to => 'day' );
140
                push @ymd_arr, $dt->ymd('');
141
            }
142
            $single_holidays->{$br} = \@ymd_arr;
143
        }    # br
144
        $cache->set_in_cache( 'single_holidays', $single_holidays,
145
            76800 )    #24 hrs ;
110
    }
146
    }
111
    $self->{single_holidays}{$branchcode} = DateTime::Set->from_datetimes( dates => $dates );
147
    my $holidays  = ( $single_holidays->{$branchcode} );
112
    $single_holidays->{$branchcode} = $self->{single_holidays}{$branchcode};
148
    for my $hols  (@$holidays ) {
113
    return $single_holidays->{$branchcode};
149
            return 1 if ( $date == $hols )   #match ymds;
150
    }
151
    return 0;
114
}
152
}
153
115
sub addDate {
154
sub addDate {
116
    my ( $self, $startdate, $add_duration, $unit ) = @_;
155
    my ( $self, $startdate, $add_duration, $unit ) = @_;
117
156
Lines 193-198 sub addDays { Link Here
193
            # Datedue, then use the calendar to push
232
            # Datedue, then use the calendar to push
194
            # the date to the next open day if holiday
233
            # the date to the next open day if holiday
195
            if ( $self->is_holiday($base_date) ) {
234
            if ( $self->is_holiday($base_date) ) {
235
196
                if ( $days_duration->is_negative() ) {
236
                if ( $days_duration->is_negative() ) {
197
                    $base_date = $self->prev_open_day($base_date);
237
                    $base_date = $self->prev_open_day($base_date);
198
                } else {
238
                } else {
Lines 207-218 sub addDays { Link Here
207
247
208
sub is_holiday {
248
sub is_holiday {
209
    my ( $self, $dt ) = @_;
249
    my ( $self, $dt ) = @_;
250
210
    my $localdt = $dt->clone();
251
    my $localdt = $dt->clone();
211
    my $day   = $localdt->day;
252
    my $day   = $localdt->day;
212
    my $month = $localdt->month;
253
    my $month = $localdt->month;
213
254
214
    $localdt->truncate( to => 'day' );
255
    $localdt->truncate( to => 'day' );
215
256
257
216
    if ( $self->exception_holidays->contains($localdt) ) {
258
    if ( $self->exception_holidays->contains($localdt) ) {
217
        # exceptions are not holidays
259
        # exceptions are not holidays
218
        return 0;
260
        return 0;
Lines 234-240 sub is_holiday { Link Here
234
        return 1;
276
        return 1;
235
    }
277
    }
236
278
237
    if ( $self->single_holidays->contains($localdt) ) {
279
    my $ymd   = $localdt->ymd('')  ;
280
    if ($self->single_holidays(  $ymd  ) == 1 ) {
238
        return 1;
281
        return 1;
239
    }
282
    }
240
283
Lines 340-358 sub clear_weekly_closed_days { Link Here
340
    return;
383
    return;
341
}
384
}
342
385
343
sub add_holiday {
344
    my $self = shift;
345
    my $new_dt = shift;
346
    my @dt = $self->single_holidays->as_list;
347
    push @dt, $new_dt;
348
    my $branchcode = $self->{branchcode};
349
    $self->{single_holidays}{$branchcode} =
350
      DateTime::Set->from_datetimes( dates => \@dt );
351
    $single_holidays->{$branchcode} = $self->{single_holidays}{$branchcode};
352
386
353
    return;
387
sub add_dummy_holiday {
388
    my ( $self, $new_dt ) = @_;
389
390
    my $cache           = Koha::Cache->get_instance();
391
    my $single_holidays = $cache->get_from_cache('single_holidays');
392
393
    # add a dummy holiday to the holiday cache...
394
    my $ymd = $new_dt->ymd('');
395
    $single_holidays->{'MPL'} = [$ymd];
396
    $cache->set_in_cache( 'single_holidays', $single_holidays, 76800 );
397
398
    # ...but *dont* reset the cache, as this holiday was not really written to the db
399
    # its only used to mock a holiday insert for 1 test in t/db_dependent/Holidays.t
400
401
    #   is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
402
    #   $koha_calendar->add_dummy_holiday($custom_holiday );
403
    #   is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
404
354
}
405
}
355
406
407
356
1;
408
1;
357
__END__
409
__END__
358
410
Lines 429-434 Currently unit is only used to invoke Staffs return Monday at 10 am rule this Link Here
429
parameter will be removed when issuingrules properly cope with that
481
parameter will be removed when issuingrules properly cope with that
430
482
431
483
484
=head2 single_holidays
485
486
my $rc = $self->single_holidays(  $ymd  );
487
488
Passed a $date in Ymd (yyyymmdd) format -  returns 1 if date is a single_holiday, or 0 if not.
489
490
432
=head2 is_holiday
491
=head2 is_holiday
433
492
434
$yesno = $calendar->is_holiday($dt);
493
$yesno = $calendar->is_holiday($dt);
(-)a/t/Calendar.t (-14 / +23 lines)
Lines 4-12 use strict; Link Here
4
use warnings;
4
use warnings;
5
use DateTime;
5
use DateTime;
6
use DateTime::Duration;
6
use DateTime::Duration;
7
use Test::More tests => 35;
7
use Test::More tests => 34;
8
use Test::MockModule;
8
use Test::MockModule;
9
use DBD::Mock;
9
use DBD::Mock;
10
use Koha::Cache;
10
use Koha::DateUtils;
11
use Koha::DateUtils;
11
12
12
BEGIN {
13
BEGIN {
Lines 14-20 BEGIN { Link Here
14
15
15
    # This was the only test C4 had
16
    # This was the only test C4 had
16
    # Remove when no longer used
17
    # Remove when no longer used
17
    use_ok('C4::Calendar');
18
    #use_ok('C4::Calendar'); # not used anymore?
18
}
19
}
19
20
20
my $module_context = new Test::MockModule('C4::Context');
21
my $module_context = new Test::MockModule('C4::Context');
Lines 66-85 my $holidays_session = DBD::Mock::Session->new('holidays_session' => ( Link Here
66
                        [ 11, 11, 2012 ] # sunday exception
67
                        [ 11, 11, 2012 ] # sunday exception
67
                     ]
68
                     ]
68
    },
69
    },
69
    { # single holidays
70
71
    { # single holidays1
72
        statement => "SELECT distinct(branchcode) FROM special_holidays",
73
        results   => [
74
                        [ 'branchcode' ],
75
                        [ 'MPL']
76
                     ]
77
    },
78
79
    { # single holidays2
70
        statement => "SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0",
80
        statement => "SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0",
71
        results   => [
81
        results   => [
72
                        [ 'day', 'month', 'year' ],
82
                        [ 'day', 'month', 'year' ],
73
                        [ 1, 6, 2011 ],  # single holiday
83
                        [ 1, 6, 2011 ],  # single holiday
74
                        [ 4, 7, 2012 ]
84
                        [ 4, 7, 2012 ]
75
                     ]
85
                     ]
76
    }
86
    },
77
));
87
));
78
88
79
# Initialize the global $dbh variable
89
# Initialize the global $dbh variable
80
my $dbh = C4::Context->dbh();
90
my $dbh = C4::Context->dbh();
81
# Apply the mock session
91
# Apply the mock session
82
$dbh->{ mock_session } = $holidays_session;
92
$dbh->{ mock_session } = $holidays_session;
93
94
95
my $cache = Koha::Cache->get_instance();
96
$cache->clear_from_cache( 'single_holidays') ;
97
98
83
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
99
# 'MPL' branch is arbitrary, is not used at all but is needed for initialization
84
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
100
my $cal = Koha::Calendar->new( branchcode => 'MPL' );
85
101
Lines 134-140 my $day_after_christmas = DateTime->new( Link Here
134
    day     => 26
150
    day     => 26
135
);  # for testing negative addDate
151
);  # for testing negative addDate
136
152
137
138
{   # Syspref-agnostic tests
153
{   # Syspref-agnostic tests
139
    is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
154
    is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)');
140
    is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
155
    is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)');
Lines 148-154 my $day_after_christmas = DateTime->new( Link Here
148
    is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
163
    is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' );
149
}
164
}
150
165
151
152
{   # Bugzilla #8966 - is_holiday truncates referenced date
166
{   # Bugzilla #8966 - is_holiday truncates referenced date
153
    my $later_dt = DateTime->new(    # Monday
167
    my $later_dt = DateTime->new(    # Monday
154
        year      => 2012,
168
        year      => 2012,
Lines 164-170 my $day_after_christmas = DateTime->new( Link Here
164
    cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
178
    cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' );
165
}
179
}
166
180
167
168
{   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
181
{   # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call
169
    my $single_holiday_time = DateTime->new(
182
    my $single_holiday_time = DateTime->new(
170
        year  => 2011,
183
        year  => 2011,
Lines 179-190 my $day_after_christmas = DateTime->new( Link Here
179
        'bz-8800 is_holiday should truncate the date for holiday validation' );
192
        'bz-8800 is_holiday should truncate the date for holiday validation' );
180
}
193
}
181
194
182
183
    my $one_day_dur = DateTime::Duration->new( days => 1 );
195
    my $one_day_dur = DateTime::Duration->new( days => 1 );
184
    my $two_day_dur = DateTime::Duration->new( days => 2 );
196
    my $two_day_dur = DateTime::Duration->new( days => 2 );
185
    my $seven_day_dur = DateTime::Duration->new( days => 7 );
197
    my $seven_day_dur = DateTime::Duration->new( days => 7 );
186
198
187
    my $dt = dt_from_string( '2012-07-03','iso' );
199
    my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday
200
188
    my $test_dt = DateTime->new(    # Monday
201
    my $test_dt = DateTime->new(    # Monday
189
        year      => 2012,
202
        year      => 2012,
190
        month     => 7,
203
        month     => 7,
Lines 202-208 my $day_after_christmas = DateTime->new( Link Here
202
        time_zone => 'Europe/London',
215
        time_zone => 'Europe/London',
203
    );
216
    );
204
217
205
206
{    ## 'Datedue' tests
218
{    ## 'Datedue' tests
207
219
208
    $module_context->unmock('preference');
220
    $module_context->unmock('preference');
Lines 218-224 my $day_after_christmas = DateTime->new( Link Here
218
230
219
    $cal = Koha::Calendar->new( branchcode => 'MPL' );
231
    $cal = Koha::Calendar->new( branchcode => 'MPL' );
220
232
221
    is($cal->addDate( $dt, $one_day_dur, 'days' ),
233
    is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday
222
        dt_from_string('2012-07-05','iso'),
234
        dt_from_string('2012-07-05','iso'),
223
        'Single day add (Datedue, matches holiday, shift)' );
235
        'Single day add (Datedue, matches holiday, shift)' );
224
236
Lines 243-253 my $day_after_christmas = DateTime->new( Link Here
243
255
244
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
256
    cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'),
245
                '==', 40, 'Test parameter order not relevant (Days)' );
257
                '==', 40, 'Test parameter order not relevant (Days)' );
246
247
248
}
258
}
249
259
250
251
{   ## 'Calendar' tests'
260
{   ## 'Calendar' tests'
252
261
253
    $module_context->unmock('preference');
262
    $module_context->unmock('preference');
(-)a/t/db_dependent/Holidays.t (-3 / +6 lines)
Lines 3-14 use warnings; Link Here
3
use 5.010;
3
use 5.010;
4
use DateTime;
4
use DateTime;
5
use DateTime::TimeZone;
5
use DateTime::TimeZone;
6
use Test::More tests => 12;
6
7
7
use C4::Context;
8
use C4::Context;
8
use Koha::DateUtils;
9
use Test::More tests => 12;
10
use C4::Branch;
9
use C4::Branch;
11
10
11
use Koha::DateUtils;
12
12
BEGIN { use_ok('Koha::Calendar'); }
13
BEGIN { use_ok('Koha::Calendar'); }
13
BEGIN { use_ok('C4::Calendar'); }
14
BEGIN { use_ok('C4::Calendar'); }
14
15
Lines 91-98 my $custom_holiday = DateTime->new( Link Here
91
    month => 11,
92
    month => 11,
92
    day   => 12,
93
    day   => 12,
93
);
94
);
95
94
is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
96
is( $koha_calendar->is_holiday($custom_holiday), 0, '2013-11-10 does not start off as a holiday' );
95
$koha_calendar->add_holiday($custom_holiday);
97
$koha_calendar->add_dummy_holiday($custom_holiday );
96
is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
98
is( $koha_calendar->is_holiday($custom_holiday), 1, 'able to add holiday for testing' );
97
99
98
my $today = dt_from_string();
100
my $today = dt_from_string();
Lines 103-108 C4::Calendar->new( branchcode => 'CPL' )->insert_single_holiday( Link Here
103
    title       => "$today",
105
    title       => "$today",
104
    description => "$today",
106
    description => "$today",
105
);
107
);
108
106
is( Koha::Calendar->new( branchcode => 'CPL' )->is_holiday( $today ), 1, "Today is a holiday for CPL" );
109
is( Koha::Calendar->new( branchcode => 'CPL' )->is_holiday( $today ), 1, "Today is a holiday for CPL" );
107
is( Koha::Calendar->new( branchcode => 'MPL' )->is_holiday( $today ), 0, "Today is not a holiday for MPL");
110
is( Koha::Calendar->new( branchcode => 'MPL' )->is_holiday( $today ), 0, "Today is not a holiday for MPL");
108
111
(-)a/tools/newHolidays.pl (-1 / +8 lines)
Lines 1-4 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#FIXME: add a license
3
#FIXME: perltidy this file
2
4
3
use strict;
5
use strict;
4
use warnings;
6
use warnings;
Lines 8-13 use CGI qw ( -utf8 ); Link Here
8
use C4::Auth;
10
use C4::Auth;
9
use C4::Output;
11
use C4::Output;
10
12
13
use Koha::Cache;
14
11
15
12
use C4::Calendar;
16
use C4::Calendar;
13
use DateTime;
17
use DateTime;
Lines 82-87 if($allbranches) { Link Here
82
86
83
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
87
print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate");
84
88
89
#FIXME: move add_holiday() to a better place
85
sub add_holiday {
90
sub add_holiday {
86
	($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;  
91
	($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_;  
87
	my $calendar = C4::Calendar->new(branchcode => $branchcode);
92
	my $calendar = C4::Calendar->new(branchcode => $branchcode);
Lines 141-144 sub add_holiday { Link Here
141
            }
146
            }
142
        }
147
        }
143
    }
148
    }
149
    # we updated the single_holidays table, so wipe its cache
150
    my $cache = Koha::Cache->get_instance();
151
    $cache->clear_from_cache( 'single_holidays') ;
144
}
152
}
145
- 

Return to bug 14522