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

(-)a/Koha/Template/Plugin/KohaTimes.pm (+41 lines)
Line 0 Link Here
1
package Koha::Template::Plugin::KohaTimes;
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
use Template::Plugin::Filter;
20
use base qw( Template::Plugin::Filter );
21
22
our $DYNAMIC = 1;
23
24
sub filter {
25
    my ( $self, $text, $args, $config ) = @_;
26
    return "" unless $text;
27
28
    my ( $hours, $minutes, $seconds ) = split( ':', $text );
29
    if ( C4::Context->preference('TimeFormat') == "12hr" ) {
30
        my $ampm = ( $hours >= 12 ) ? 'pm' : 'am';
31
        $hours = ( $hours == 0 ) ? "12"            : $hours;
32
        $hours = ( $hours > 12 ) ? ( $hours - 12 ) : $hours;
33
        $hours = sprintf '%.2u', $hours;
34
35
        return "$hours:$minutes $ampm";
36
    } else {
37
        return "$hours:$minutes";
38
    }
39
}
40
41
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc (-1 / +7 lines)
Lines 85-95 Link Here
85
                        instance.set('allowInput',false);
85
                        instance.set('allowInput',false);
86
                    }
86
                    }
87
                });
87
                });
88
89
            /* When flatpickr instance is ready, add maskito input mask */
88
            /* When flatpickr instance is ready, add maskito input mask */
90
            var thisInput = instance.input;
89
            var thisInput = instance.input;
91
            let accepts_time = $(thisInput).data('flatpickr-enable-time');
90
            let accepts_time = $(thisInput).data('flatpickr-enable-time');
92
            let accepts_period = $(thisInput).data('flatpickr-period');
91
            let accepts_period = $(thisInput).data('flatpickr-period');
92
            let accepts_time_only = $(thisInput).data('flatpickr-time-only');
93
            let maskitoOptions = {};
93
            let maskitoOptions = {};
94
            if ( !accepts_period ) {
94
            if ( !accepts_period ) {
95
                if ( accepts_time ) {
95
                if ( accepts_time ) {
Lines 99-104 Link Here
99
                        dateSeparator: delimiter,
99
                        dateSeparator: delimiter,
100
                        overwiteMode: 'replace',
100
                        overwiteMode: 'replace',
101
                    });
101
                    });
102
                } else if ( accepts_time_only ) {
103
                    maskitoOptions = maskitoTimeOptionsGenerator({
104
                    });
102
                } else {
105
                } else {
103
                    maskitoOptions = maskitoDateOptionsGenerator({
106
                    maskitoOptions = maskitoDateOptionsGenerator({
104
                        mode: altinput_dateformat,
107
                        mode: altinput_dateformat,
Lines 112-117 Link Here
112
        onChange: function( selectedDates, dateText, instance) {
115
        onChange: function( selectedDates, dateText, instance) {
113
            var thisInput = instance.input;
116
            var thisInput = instance.input;
114
            let accepts_time = $(thisInput).data('flatpickr-enable-time');
117
            let accepts_time = $(thisInput).data('flatpickr-enable-time');
118
            let accepts_time_only = $(thisInput).data('flatpickr-time-only');
115
            let accepts_period = $(thisInput).data('flatpickr-period');
119
            let accepts_period = $(thisInput).data('flatpickr-period');
116
            if ( !accepts_period ) {
120
            if ( !accepts_period ) {
117
                if ( accepts_time ) {
121
                if ( accepts_time ) {
Lines 234-239 Link Here
234
            options['enableTime'] = true;
238
            options['enableTime'] = true;
235
            options['noCalendar'] = true;
239
            options['noCalendar'] = true;
236
            options['dateFormat'] = "H:i";
240
            options['dateFormat'] = "H:i";
241
            options['defaultHour'] = "0";
242
            options['defaultMinute'] = "0";
237
            options['altFormat'] = flatpickr_timeformat_string;
243
            options['altFormat'] = flatpickr_timeformat_string;
238
            options['plugins'] = [];
244
            options['plugins'] = [];
239
        }
245
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc (-1 / +26 lines)
Lines 34-40 Link Here
34
        };
34
        };
35
35
36
        /**
36
        /**
37
         * A JS equivilent of the KohaDates TT Plugin. Passed an rfc3339 formatted date string,
37
         * A JS equivalent of the KohaDates TT Plugin. Passed an rfc3339 formatted date string,
38
         * or JS Date, the function will return a date string formatted as per the koha instance config.
38
         * or JS Date, the function will return a date string formatted as per the koha instance config.
39
         * @param {String|Date} value                   rfc3339 formatted date string or a JS Date object.
39
         * @param {String|Date} value                   rfc3339 formatted date string or a JS Date object.
40
         * @param {Object} [options]                    Optional set of switches for changing date handling
40
         * @param {Object} [options]                    Optional set of switches for changing date handling
Lines 95-100 Link Here
95
            return m.format("YYYY-MM-DD");
95
            return m.format("YYYY-MM-DD");
96
        }
96
        }
97
97
98
        /**
99
        * A JS equivalent of the KohaTimes TT Plugin. Passed a time in HH:MM:SS or HH:MM format
100
        * the function will return a time string formatted as per the koha instance config.
101
        */
102
103
        window.$kohatime = function(value) {
104
            if(!value) return 'invalid time';
105
            var intime = value.split(':');
106
            var hours = intime[0];
107
            var minutes = intime[1];
108
109
            if ( hours < 0 || hours > 23 || minutes < 0 || minutes > 59 ) { return 'invalid time'; }
110
111
            if ( def_time_format == '12hr') {
112
                var ampm = ( hours >= 12 ) ? 'pm' : 'am';
113
                hours = ( hours == 0 ) ? "12" : hours;
114
                hours = ( hours > 12 ) ? ( hours - 12 ) : hours;
115
116
                return hours.toString().padStart(2,'0') + ':' + minutes.toString().padStart(2,'0') + " " + ampm;
117
            } else {
118
                return hours.toString().padStart(2,'0') + ':' + minutes.toString().padStart(2,'0');
119
            }
120
        }
121
122
98
    })();
123
    })();
99
</script>
124
</script>
100
<!-- / js-date-format.inc -->
125
<!-- / js-date-format.inc -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-6 / +27 lines)
Lines 3-8 Link Here
3
[% USE Asset %]
3
[% USE Asset %]
4
[% USE TablesSettings %]
4
[% USE TablesSettings %]
5
[%- USE KohaSpan -%]
5
[%- USE KohaSpan -%]
6
[% USE KohaTimes %]
6
[% PROCESS 'i18n.inc' %]
7
[% PROCESS 'i18n.inc' %]
7
[% SET footerjs = 1 %]
8
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
Lines 556-562 Link Here
556
                    </li>
557
                    </li>
557
                    <li>
558
                    <li>
558
                        <span class="label">Opening hours: </span>
559
                        <span class="label">Opening hours: </span>
559
                        [% IF library.library_hours.count > 0 # Existing library %]
560
                        [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %]
561
                        [% SET set_hours = 0 %]
562
                        [% IF library.library_hours.count > 0 %]
563
                            [% FOR i IN [0..6] %]
564
                                [% IF library.library_hours.as_list.$i.open_time != null || library.library_hours.as_list.$i.close_time != null %]
565
                                    [% set_hours = 1 %]
566
                                [% END %]
567
                            [% END %]
568
                        [% END %]
569
                        [% IF set_hours > 0 # Existing library %]
560
                            [% SET library_hours = library.library_hours.as_list %]
570
                            [% SET library_hours = library.library_hours.as_list %]
561
                            <table id="library_hours_table">
571
                            <table id="library_hours_table">
562
                                <thead>
572
                                <thead>
Lines 575-584 Link Here
575
                                            <span>[% PROCESS dayname day=d %]</span>
585
                                            <span>[% PROCESS dayname day=d %]</span>
576
                                        </td>
586
                                        </td>
577
                                        <td>
587
                                        <td>
578
                                            <span>[% hr.open_time | html %]</span>
588
                                            <span>[% IF hr.open_time != null %][% hr.open_time | $KohaTimes %][% END %]</span>
579
                                        </td>
589
                                        </td>
580
                                        <td>
590
                                        <td>
581
                                            <span>[% hr.close_time | html %]</span>
591
                                            <span>[% IF hr.close_time != null %][% hr.close_time | $KohaTimes %][% END %]</span>
582
                                        </td>
592
                                        </td>
583
                                    </tr>
593
                                    </tr>
584
                                    [% END %]
594
                                    [% END %]
Lines 757-763 Link Here
757
                    {
767
                    {
758
                        "data": function( row, type, val, meta ) {
768
                        "data": function( row, type, val, meta ) {
759
                            let result = '';
769
                            let result = '';
770
                            let set_hours = 0;
760
                            if ( row.library_hours.length > 0 ) {
771
                            if ( row.library_hours.length > 0 ) {
772
                                for (let check_counter = 0; check_counter < 7; check_counter++) {
773
                                    if ( row.library_hours[check_counter].open_time != null || row.library_hours[check_counter].close_time != null ) {
774
                                        set_hours = 1;
775
                                    }
776
                                }
777
                            }
778
                            if ( set_hours > 0 ) {
761
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
779
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
762
780
763
                                result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
781
                                result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
Lines 766-773 Link Here
766
                                    const day = i % 7; // Wrap around the day using modulo operator
784
                                    const day = i % 7; // Wrap around the day using modulo operator
767
                                    result += '<tr id="hours_'+day+'">';
785
                                    result += '<tr id="hours_'+day+'">';
768
                                    result += '<td>'+daysOfWeek[day]+'</td>';
786
                                    result += '<td>'+daysOfWeek[day]+'</td>';
769
                                    result += '<td><span>'+row.library_hours[day].open_time+'</span></td>';
787
                                    result += '<td><span>';
770
                                    result += '<td><span>'+row.library_hours[day].close_time+'</span></td>';
788
                                    result += row.library_hours[day].open_time != null ? $kohatime(row.library_hours[day].open_time): '';
789
                                    result += '</span></td>';
790
                                    result += '<td><span>';
791
                                    result += row.library_hours[day].close_time != null ? $kohatime(row.library_hours[day].close_time): '';
792
                                    result += '</span></td>';
771
                                    result += '</tr>';
793
                                    result += '</tr>';
772
                                    counter++;
794
                                    counter++;
773
                                }
795
                                }
774
- 

Return to bug 36594