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

(-)a/Koha/Calendar.pm (-6 / +27 lines)
Lines 1-14 Link Here
1
package Koha::Calendar;
1
package Koha::Calendar;
2
use strict;
3
use warnings;
4
use 5.010;
5
2
3
use Modern::Perl;
4
5
use Carp;
6
use DateTime;
6
use DateTime;
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::Caches;
10
use Koha::Caches;
11
use Carp;
11
use Koha::Exceptions;
12
12
13
sub new {
13
sub new {
14
    my ( $classname, %options ) = @_;
14
    my ( $classname, %options ) = @_;
Lines 47-53 sub _init { Link Here
47
          1;
47
          1;
48
    }
48
    }
49
49
50
    $self->{days_mode}       ||= C4::Context->preference('useDaysMode');
51
    $self->{test}            = 0;
50
    $self->{test}            = 0;
52
    return;
51
    return;
53
}
52
}
Lines 137-142 sub single_holidays { Link Here
137
sub addDate {
136
sub addDate {
138
    my ( $self, $startdate, $add_duration, $unit ) = @_;
137
    my ( $self, $startdate, $add_duration, $unit ) = @_;
139
138
139
140
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDate: days_mode")
141
        unless exists $self->{days_mode};
142
140
    # Default to days duration (legacy support I guess)
143
    # Default to days duration (legacy support I guess)
141
    if ( ref $add_duration ne 'DateTime::Duration' ) {
144
    if ( ref $add_duration ne 'DateTime::Duration' ) {
142
        $add_duration = DateTime::Duration->new( days => $add_duration );
145
        $add_duration = DateTime::Duration->new( days => $add_duration );
Lines 165-170 sub addHours { Link Here
165
    # If we are using the calendar behave for now as if Datedue
168
    # If we are using the calendar behave for now as if Datedue
166
    # was the chosen option (current intended behaviour)
169
    # was the chosen option (current intended behaviour)
167
170
171
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addHours: days_mode")
172
        unless exists $self->{days_mode};
173
168
    if ( $self->{days_mode} ne 'Days' &&
174
    if ( $self->{days_mode} ne 'Days' &&
169
          $self->is_holiday($base_date) ) {
175
          $self->is_holiday($base_date) ) {
170
176
Lines 185-191 sub addDays { Link Here
185
    my ( $self, $startdate, $days_duration ) = @_;
191
    my ( $self, $startdate, $days_duration ) = @_;
186
    my $base_date = $startdate->clone();
192
    my $base_date = $startdate->clone();
187
193
188
    $self->{days_mode} ||= q{};
194
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDays: days_mode")
195
        unless exists $self->{days_mode};
189
196
190
    if ( $self->{days_mode} eq 'Calendar' ) {
197
    if ( $self->{days_mode} eq 'Calendar' ) {
191
        # use the calendar to skip all days the library is closed
198
        # use the calendar to skip all days the library is closed
Lines 235-240 sub addDays { Link Here
235
sub get_push_amt {
242
sub get_push_amt {
236
    my ( $self, $base_date) = @_;
243
    my ( $self, $base_date) = @_;
237
244
245
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->get_push_amt: days_mode")
246
        unless exists $self->{days_mode};
247
238
    my $dow = $base_date->day_of_week;
248
    my $dow = $base_date->day_of_week;
239
    return (
249
    return (
240
        # We're using Dayweek useDaysMode option
250
        # We're using Dayweek useDaysMode option
Lines 288-293 sub is_holiday { Link Here
288
298
289
sub next_open_days {
299
sub next_open_days {
290
    my ( $self, $dt, $to_add ) = @_;
300
    my ( $self, $dt, $to_add ) = @_;
301
302
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->next_open_days: days_mode")
303
        unless exists $self->{days_mode};
304
291
    my $base_date = $dt->clone();
305
    my $base_date = $dt->clone();
292
306
293
    $base_date->add(days => $to_add);
307
    $base_date->add(days => $to_add);
Lines 300-305 sub next_open_days { Link Here
300
314
301
sub prev_open_days {
315
sub prev_open_days {
302
    my ( $self, $dt, $to_sub ) = @_;
316
    my ( $self, $dt, $to_sub ) = @_;
317
318
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->get_open_days: days_mode")
319
        unless exists $self->{days_mode};
320
303
    my $base_date = $dt->clone();
321
    my $base_date = $dt->clone();
304
322
305
    # It feels logical to be passed a positive number, though we're
323
    # It feels logical to be passed a positive number, though we're
Lines 323-328 sub days_forward { Link Here
323
    my $start_dt = shift;
341
    my $start_dt = shift;
324
    my $num_days = shift;
342
    my $num_days = shift;
325
343
344
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->days_forward: days_mode")
345
        unless exists $self->{days_mode};
346
326
    return $start_dt unless $num_days > 0;
347
    return $start_dt unless $num_days > 0;
327
348
328
    my $base_dt = $start_dt->clone();
349
    my $base_dt = $start_dt->clone();
(-)a/Koha/CirculationRules.pm (-1 / +3 lines)
Lines 109-114 our $RULE_KINDS = { Link Here
109
    issuelength => {
109
    issuelength => {
110
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
110
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
111
    },
111
    },
112
    useDaysMode => {
113
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
114
    },
112
    lengthunit => {
115
    lengthunit => {
113
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
116
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
114
    },
117
    },
115
- 

Return to bug 24159