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

(-)a/C4/Calendar.pm (-7 / +11 lines)
Lines 644-650 C<$year> Is the year to check whether if is a holiday or not. Link Here
644
sub isHoliday {
644
sub isHoliday {
645
    my ($self, $day, $month, $year) = @_;
645
    my ($self, $day, $month, $year) = @_;
646
	# FIXME - date strings are stored in non-padded metric format. should change to iso.
646
	# FIXME - date strings are stored in non-padded metric format. should change to iso.
647
	# FIXME - should change arguments to accept C4::Dates object
648
	$month=$month+0;
647
	$month=$month+0;
649
	$year=$year+0;
648
	$year=$year+0;
650
	$day=$day+0;
649
	$day=$day+0;
Lines 700-706 sub copy_to_branch { Link Here
700
699
701
    my ($day, $month, $year) = $calendar->addDate($date, $offset)
700
    my ($day, $month, $year) = $calendar->addDate($date, $offset)
702
701
703
C<$date> is a C4::Dates object representing the starting date of the interval.
702
C<$startdate> is the starting date of the interval.
704
703
705
C<$offset> Is the number of days that this function has to count from $date.
704
C<$offset> Is the number of days that this function has to count from $date.
706
705
Lines 708-714 C<$offset> Is the number of days that this function has to count from $date. Link Here
708
707
709
sub addDate {
708
sub addDate {
710
    my ($self, $startdate, $offset) = @_;
709
    my ($self, $startdate, $offset) = @_;
711
    my ($year,$month,$day) = split("-",$startdate->output('iso'));
710
    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
711
    my ( $year, $month, $day) = split( "-", $startdate );
712
	my $daystep = 1;
712
	my $daystep = 1;
713
	if ($offset < 0) { # In case $offset is negative
713
	if ($offset < 0) { # In case $offset is negative
714
       # $offset = $offset*(-1);
714
       # $offset = $offset*(-1);
Lines 730-743 sub addDate { Link Here
730
	} else { ## ($daysMode eq 'Days') 
730
	} else { ## ($daysMode eq 'Days') 
731
        ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
731
        ($year, $month, $day) = &Date::Calc::Add_Delta_Days($year, $month, $day, $offset );
732
    }
732
    }
733
    return(C4::Dates->new( sprintf(ISO_DATE_FORMAT,$year,$month,$day),'iso'));
733
    my $date_ret = sprintf(ISO_DATE_FORMAT,$year,$month,$day);
734
    $date_ret =  eval { output_pref( { dt => dt_from_string( $date_ret), dateonly => 1, dateformat => 'iso' } ); };
735
    return($date_ret);
734
}
736
}
735
737
736
=head2 daysBetween
738
=head2 daysBetween
737
739
738
    my $daysBetween = $calendar->daysBetween($startdate, $enddate)
740
    my $daysBetween = $calendar->daysBetween($startdate, $enddate)
739
741
740
C<$startdate> and C<$enddate> are C4::Dates objects that define the interval.
742
C<$startdate> and C<$enddate> define the interval.
741
743
742
Returns the number of non-holiday days in the interval.
744
Returns the number of non-holiday days in the interval.
743
useDaysMode syspref has no effect here.
745
useDaysMode syspref has no effect here.
Lines 747-754 sub daysBetween { Link Here
747
    my $self      = shift or return;
749
    my $self      = shift or return;
748
    my $startdate = shift or return;
750
    my $startdate = shift or return;
749
    my $enddate   = shift or return;
751
    my $enddate   = shift or return;
750
    my ($yearFrom,$monthFrom,$dayFrom) = split("-",$startdate->output('iso'));
752
    $startdate = eval { output_pref( { dt => dt_from_string( $startdate ), dateonly => 1, dateformat => 'iso' } ); };
751
    my ($yearTo,  $monthTo,  $dayTo  ) = split("-",  $enddate->output('iso'));
753
    $enddate = eval { output_pref( { dt => dt_from_string( $enddate ), dateonly => 1, dateformat => 'iso' } ); };
754
    my ( $yearFrom, $monthFrom, $dayFrom) = split( "-", $startdate);
755
    my ( $yearTo,  $monthTo,  $dayTo  ) = split( "-",  $enddate);
752
    if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
756
    if (Date_to_Days($yearFrom,$monthFrom,$dayFrom) > Date_to_Days($yearTo,$monthTo,$dayTo)) {
753
        return 0;
757
        return 0;
754
        # we don't go backwards  ( FIXME - handle this error better )
758
        # we don't go backwards  ( FIXME - handle this error better )
(-)a/tools/exceptionHolidays.pl (-25 / +4 lines)
Lines 10-15 use C4::Output; Link Here
10
use DateTime;
10
use DateTime;
11
11
12
use C4::Calendar;
12
use C4::Calendar;
13
use Koha::DateUtils;
13
14
14
my $input = new CGI;
15
my $input = new CGI;
15
my $dbh = C4::Context->dbh();
16
my $dbh = C4::Context->dbh();
Lines 19-34 my $weekday = $input->param('showWeekday'); Link Here
19
my $day = $input->param('showDay');
20
my $day = $input->param('showDay');
20
my $month = $input->param('showMonth');
21
my $month = $input->param('showMonth');
21
my $year = $input->param('showYear');
22
my $year = $input->param('showYear');
22
my $day1;
23
my $month1;
24
my $year1;
25
my $title = $input->param('showTitle');
23
my $title = $input->param('showTitle');
26
my $description = $input->param('showDescription');
24
my $description = $input->param('showDescription');
27
my $holidaytype = $input->param('showHolidayType');
25
my $holidaytype = $input->param('showHolidayType');
28
my $datecancelrange = $input->param('datecancelrange');
26
my $datecancelrange_dt = eval { dt_from_string( $input->param('datecancelrange') ) };
29
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
27
my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day);
30
my $isodate = C4::Dates->new($calendardate, 'iso');
31
$calendardate = $isodate->output('syspref');
32
28
33
my $calendar = C4::Calendar->new(branchcode => $branchcode);
29
my $calendar = C4::Calendar->new(branchcode => $branchcode);
34
30
Lines 40-69 if ($description) { Link Here
40
    $description = '';
36
    $description = '';
41
}   
37
}   
42
38
43
# We format the date
44
my @dateend = split(/[\/-]/, $datecancelrange);
45
if (C4::Context->preference("dateformat") eq "metric") {
46
    $day1 = $dateend[0];
47
    $month1 = $dateend[1];
48
    $year1 = $dateend[2];
49
}elsif (C4::Context->preference("dateformat") eq "us") {
50
    $month1 = $dateend[0];
51
    $day1 = $dateend[1];
52
    $year1 = $dateend[2];
53
} else {
54
    $year1 = $dateend[0];
55
    $month1 = $dateend[1];
56
    $day1 = $dateend[2];
57
}
58
59
# We make an array with holiday's days
39
# We make an array with holiday's days
60
my @holiday_list;
40
my @holiday_list;
61
if ($year1 && $month1 && $day1){
41
if ($datecancelrange_dt){
62
            my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
42
            my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
63
            my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
64
43
65
            for (my $dt = $first_dt->clone();
44
            for (my $dt = $first_dt->clone();
66
                $dt <= $end_dt;
45
                $dt <= $datecancelrange_dt;
67
                $dt->add(days => 1) )
46
                $dt->add(days => 1) )
68
                {
47
                {
69
                push @holiday_list, $dt->clone();
48
                push @holiday_list, $dt->clone();
(-)a/tools/holidays.pl (-12 / +8 lines)
Lines 26-31 use C4::Output; Link Here
26
26
27
use C4::Branch; # GetBranches
27
use C4::Branch; # GetBranches
28
use C4::Calendar;
28
use C4::Calendar;
29
use Koha::DateUtils;
29
30
30
my $input = new CGI;
31
my $input = new CGI;
31
32
Lines 44-58 my ($template, $loggedinuser, $cookie) Link Here
44
my $keydate;
45
my $keydate;
45
# calendardate - date passed in url for human readability (syspref)
46
# calendardate - date passed in url for human readability (syspref)
46
my $calendardate;
47
my $calendardate;
47
my $today = C4::Dates->new();
48
my $calendarinput_dt = eval { dt_from_string( $input->param('calendardate') ); } || dt_from_string;
48
my $calendarinput = C4::Dates->new($input->param('calendardate')) || $today;
49
# if the url has an invalid date default to 'now.'
49
# if the url has an invalid date default to 'now.'
50
unless($calendardate = $calendarinput->output('syspref')) {
50
$calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } );
51
  $calendardate = $today->output('syspref');
51
$keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } );
52
}
53
unless($keydate = $calendarinput->output('iso')) {
54
  $keydate = $today->output('iso');
55
}
56
$keydate =~ s/-/\//g;
52
$keydate =~ s/-/\//g;
57
53
58
my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
54
my $branch= $input->param('branch') || C4::Context->userenv->{'branch'};
Lines 123-133 foreach my $monthDay (keys %$day_month_holidays) { Link Here
123
my $exception_holidays = $calendar->get_exception_holidays();
119
my $exception_holidays = $calendar->get_exception_holidays();
124
my @exception_holidays;
120
my @exception_holidays;
125
foreach my $yearMonthDay (keys %$exception_holidays) {
121
foreach my $yearMonthDay (keys %$exception_holidays) {
126
    my $exceptiondate = C4::Dates->new($exception_holidays->{$yearMonthDay}{date}, "iso");
122
    my $exceptiondate = eval { dt_from_string( $exception_holidays->{$yearMonthDay}{date} ) };
127
    my %exception_holiday;
123
    my %exception_holiday;
128
    %exception_holiday = (KEY => $yearMonthDay,
124
    %exception_holiday = (KEY => $yearMonthDay,
129
                          DATE_SORT => $exception_holidays->{$yearMonthDay}{date},
125
                          DATE_SORT => $exception_holidays->{$yearMonthDay}{date},
130
                          DATE => $exceptiondate->output("syspref"),
126
                          DATE => output_pref( { dt => $exceptiondate, dateonly => 1, dateformat => 'iso' } ),
131
                          TITLE => $exception_holidays->{$yearMonthDay}{title},
127
                          TITLE => $exception_holidays->{$yearMonthDay}{title},
132
                          DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
128
                          DESCRIPTION => $exception_holidays->{$yearMonthDay}{description});
133
    push @exception_holidays, \%exception_holiday;
129
    push @exception_holidays, \%exception_holiday;
Lines 136-146 foreach my $yearMonthDay (keys %$exception_holidays) { Link Here
136
my $single_holidays = $calendar->get_single_holidays();
132
my $single_holidays = $calendar->get_single_holidays();
137
my @holidays;
133
my @holidays;
138
foreach my $yearMonthDay (keys %$single_holidays) {
134
foreach my $yearMonthDay (keys %$single_holidays) {
139
    my $holidaydate = C4::Dates->new($single_holidays->{$yearMonthDay}{date}, "iso");
135
    my $holidaydate = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) };
140
    my %holiday;
136
    my %holiday;
141
    %holiday = (KEY => $yearMonthDay,
137
    %holiday = (KEY => $yearMonthDay,
142
                DATE_SORT => $single_holidays->{$yearMonthDay}{date},
138
                DATE_SORT => $single_holidays->{$yearMonthDay}{date},
143
                DATE => $holidaydate->output("syspref"),
139
                DATE => output_pref( { dt => $holidaydate, dateonly => 1, dateformat => 'iso' } ),
144
                TITLE => $single_holidays->{$yearMonthDay}{title},
140
                TITLE => $single_holidays->{$yearMonthDay}{title},
145
                DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
141
                DESCRIPTION => $single_holidays->{$yearMonthDay}{description});
146
    push @holidays, \%holiday;
142
    push @holidays, \%holiday;
(-)a/tools/newHolidays.pl (-33 / +14 lines)
Lines 12-20 use C4::Output; Link Here
12
12
13
use Koha::Cache;
13
use Koha::Cache;
14
14
15
use C4::Dates;
16
use C4::Calendar;
15
use C4::Calendar;
17
use DateTime;
16
use DateTime;
17
use Koha::DateUtils;
18
18
19
my $input               = new CGI;
19
my $input               = new CGI;
20
my $dbh                 = C4::Context->dbh();
20
my $dbh                 = C4::Context->dbh();
Lines 25-57 our $weekday = $input->param('newWeekday'); Link Here
25
our $day                 = $input->param('newDay');
25
our $day                 = $input->param('newDay');
26
our $month               = $input->param('newMonth');
26
our $month               = $input->param('newMonth');
27
our $year                = $input->param('newYear');
27
our $year                = $input->param('newYear');
28
my $day1;
29
my $month1;
30
my $year1;
31
my $dateofrange         = $input->param('dateofrange');
28
my $dateofrange         = $input->param('dateofrange');
32
our $title               = $input->param('newTitle');
29
our $title               = $input->param('newTitle');
33
our $description         = $input->param('newDescription');
30
our $description         = $input->param('newDescription');
34
our $newoperation        = $input->param('newOperation');
31
our $newoperation        = $input->param('newOperation');
35
my $allbranches         = $input->param('allBranches');
32
my $allbranches         = $input->param('allBranches');
36
33
37
my $calendardate        = sprintf("%04d-%02d-%02d", $year, $month, $day);
34
38
my $isodate             = C4::Dates->new($calendardate, 'iso');
35
my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
39
$calendardate           = $isodate->output('syspref');
36
my $end_dt   = eval { dt_from_string( $dateofrange ); };
40
37
41
my @dateend = split(/[\/-]/, $dateofrange);
38
my $calendardate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } );
42
if (C4::Context->preference("dateformat") eq "metric") {
39
43
    $day1 = $dateend[0];
44
    $month1 = $dateend[1];
45
    $year1 = $dateend[2];
46
}elsif (C4::Context->preference("dateformat") eq "us") {
47
    $month1 = $dateend[0];
48
    $day1 = $dateend[1];
49
    $year1 = $dateend[2];
50
} else {
51
    $year1 = $dateend[0];
52
    $month1 = $dateend[1];
53
    $day1 = $dateend[2];
54
}
55
$title || ($title = '');
40
$title || ($title = '');
56
if ($description) {
41
if ($description) {
57
	$description =~ s/\r/\\r/g;
42
	$description =~ s/\r/\\r/g;
Lines 62-77 if ($description) { Link Here
62
47
63
# We make an array with holiday's days
48
# We make an array with holiday's days
64
our @holiday_list;
49
our @holiday_list;
65
if ($year1 && $month1 && $day1){
50
if ($end_dt){
66
            my $first_dt = DateTime->new(year => $year, month  => $month,  day => $day);
51
    for (my $dt = $first_dt->clone();
67
            my $end_dt   = DateTime->new(year => $year1, month  => $month1,  day => $day1);
52
    $dt <= $end_dt;
68
53
    $dt->add(days => 1) )
69
            for (my $dt = $first_dt->clone();
54
    {
70
                $dt <= $end_dt;
55
        push @holiday_list, $dt->clone();
71
                $dt->add(days => 1) )
56
    }
72
                {
73
                push @holiday_list, $dt->clone();
74
                }
75
}
57
}
76
58
77
if($allbranches) {
59
if($allbranches) {
78
- 

Return to bug 14954