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

(-)a/Koha/Template/Plugin/KohaTimes.pm (+42 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
    }
37
    else {
38
        return "$hours:$minutes";
39
    }
40
}
41
42
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 / +6 lines)
Lines 80-92 Link Here
80
        window.$time = function(value, options) {
80
        window.$time = function(value, options) {
81
            if(!value) return '';
81
            if(!value) return '';
82
            var tz = (options&&options.tz)||def_tz;
82
            var tz = (options&&options.tz)||def_tz;
83
            var localtime = (options&&options.localtime)||false;
83
            var m = dayjs(value);
84
            var m = dayjs(value);
84
            if(tz) m = m.tz(tz);
85
            if(tz) m = m.tz(tz);
85
86
86
            var dateformat = (options&&options.dateformat);
87
            var dateformat = (options&&options.dateformat);
87
            var timeformat = (dateformat=='rfc3339'&&'24hr')||(options&&options.timeformat)||def_time_format;
88
            var timeformat = (dateformat=='rfc3339'&&'24hr')||(options&&options.timeformat)||def_time_format;
88
89
89
            return m.format(get_time_pattern(timeformat)+(dateformat=='rfc3339'?':ss'+(!m.isUTC()?'Z':''):''))+(dateformat=='rfc3339' && m.isUTC()?'Z':'');
90
            if(localtime) {
91
                return m.local().format(get_time_pattern(timeformat)+(dateformat=='rfc3339'?':ss'+(!m.isUTC()?'Z':''):''))+(dateformat=='rfc3339' && m.isUTC()?'Z':'');
92
            } else {
93
                return m.format(get_time_pattern(timeformat)+(dateformat=='rfc3339'?':ss'+(!m.isUTC()?'Z':''):''))+(dateformat=='rfc3339' && m.isUTC()?'Z':'');
94
            }
90
        }
95
        }
91
96
92
        window.$date_to_rfc3339 = function(value, options) {
97
        window.$date_to_rfc3339 = function(value, options) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-6 / +28 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-587 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 %]
595
                                    </tr>
585
                                </tbody>
596
                                </tbody>
586
                            </table>
597
                            </table>
587
                        [% ELSE %]
598
                        [% ELSE %]
Lines 757-763 Link Here
757
                    {
768
                    {
758
                        "data": function( row, type, val, meta ) {
769
                        "data": function( row, type, val, meta ) {
759
                            let result = '';
770
                            let result = '';
771
                            let set_hours = 0;
760
                            if ( row.library_hours.length > 0 ) {
772
                            if ( row.library_hours.length > 0 ) {
773
                                for (let check_counter = 0; check_counter < 7; check_counter++) {
774
                                    if ( row.library_hours[check_counter].open_time != null || row.library_hours[check_counter].close_time != null ) {
775
                                        set_hours = 1;
776
                                    }
777
                                }
778
                            }
779
                            if ( set_hours > 0 ) {
761
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
780
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
762
781
763
                                result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
782
                                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
785
                                    const day = i % 7; // Wrap around the day using modulo operator
767
                                    result += '<tr id="hours_'+day+'">';
786
                                    result += '<tr id="hours_'+day+'">';
768
                                    result += '<td>'+daysOfWeek[day]+'</td>';
787
                                    result += '<td>'+daysOfWeek[day]+'</td>';
769
                                    result += '<td><span>'+row.library_hours[day].open_time+'</span></td>';
788
                                    result += '<td><span>';
770
                                    result += '<td><span>'+row.library_hours[day].close_time+'</span></td>';
789
                                    result += row.library_hours[day].open_time != null ? $time(row.library_hours[day].open_time + " 2000-01-03" , { localtime: true })  : '';
790
                                    result += '</span></td>';
791
                                    result += '<td><span>';
792
                                    result += row.library_hours[day].close_time != null ? $time(row.library_hours[day].close_time + " 2000-01-03", { localtime: true }): '';
793
                                    result += '</span></td>';
771
                                    result += '</tr>';
794
                                    result += '</tr>';
772
                                    counter++;
795
                                    counter++;
773
                                }
796
                                }
774
- 

Return to bug 36594