diff --git a/Koha/Template/Plugin/KohaTimes.pm b/Koha/Template/Plugin/KohaTimes.pm new file mode 100644 index 0000000000..c65c68eaf6 --- /dev/null +++ b/Koha/Template/Plugin/KohaTimes.pm @@ -0,0 +1,41 @@ +package Koha::Template::Plugin::KohaTimes; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Template::Plugin::Filter; +use base qw( Template::Plugin::Filter ); + +our $DYNAMIC = 1; + +sub filter { + my ( $self, $text, $args, $config ) = @_; + return "" unless $text; + + my ( $hours, $minutes, $seconds ) = split( ':', $text ); + if ( C4::Context->preference('TimeFormat') == "12hr" ) { + my $ampm = ( $hours >= 12 ) ? 'pm' : 'am'; + $hours = ( $hours == 0 ) ? "12" : $hours; + $hours = ( $hours > 12 ) ? ( $hours - 12 ) : $hours; + $hours = sprintf '%.2u', $hours; + + return "$hours:$minutes $ampm"; + } else { + return "$hours:$minutes"; + } +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 9f1cdb6ceb..8280be9ba9 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -85,11 +85,11 @@ instance.set('allowInput',false); } }); - /* When flatpickr instance is ready, add maskito input mask */ var thisInput = instance.input; let accepts_time = $(thisInput).data('flatpickr-enable-time'); let accepts_period = $(thisInput).data('flatpickr-period'); + let accepts_time_only = $(thisInput).data('flatpickr-time-only'); let maskitoOptions = {}; if ( !accepts_period ) { if ( accepts_time ) { @@ -99,6 +99,9 @@ dateSeparator: delimiter, overwiteMode: 'replace', }); + } else if ( accepts_time_only ) { + maskitoOptions = maskitoTimeOptionsGenerator({ + }); } else { maskitoOptions = maskitoDateOptionsGenerator({ mode: altinput_dateformat, @@ -112,6 +115,7 @@ onChange: function( selectedDates, dateText, instance) { var thisInput = instance.input; let accepts_time = $(thisInput).data('flatpickr-enable-time'); + let accepts_time_only = $(thisInput).data('flatpickr-time-only'); let accepts_period = $(thisInput).data('flatpickr-period'); if ( !accepts_period ) { if ( accepts_time ) { @@ -234,6 +238,8 @@ options['enableTime'] = true; options['noCalendar'] = true; options['dateFormat'] = "H:i"; + options['defaultHour'] = "0"; + options['defaultMinute'] = "0"; options['altFormat'] = flatpickr_timeformat_string; options['plugins'] = []; } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc index bce0620c48..73bc40b695 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc @@ -34,7 +34,7 @@ }; /** - * A JS equivilent of the KohaDates TT Plugin. Passed an rfc3339 formatted date string, + * A JS equivalent of the KohaDates TT Plugin. Passed an rfc3339 formatted date string, * or JS Date, the function will return a date string formatted as per the koha instance config. * @param {String|Date} value rfc3339 formatted date string or a JS Date object. * @param {Object} [options] Optional set of switches for changing date handling @@ -95,6 +95,31 @@ return m.format("YYYY-MM-DD"); } + /** + * A JS equivalent of the KohaTimes TT Plugin. Passed a time in HH:MM:SS or HH:MM format + * the function will return a time string formatted as per the koha instance config. + */ + + window.$kohatime = function(value) { + if(!value) return 'invalid time'; + var intime = value.split(':'); + var hours = intime[0]; + var minutes = intime[1]; + + if ( hours < 0 || hours > 23 || minutes < 0 || minutes > 59 ) { return 'invalid time'; } + + if ( def_time_format == '12hr') { + var ampm = ( hours >= 12 ) ? 'pm' : 'am'; + hours = ( hours == 0 ) ? "12" : hours; + hours = ( hours > 12 ) ? ( hours - 12 ) : hours; + + return hours.toString().padStart(2,'0') + ':' + minutes.toString().padStart(2,'0') + " " + ampm; + } else { + return hours.toString().padStart(2,'0') + ':' + minutes.toString().padStart(2,'0'); + } + } + + })(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt index af6062a9e9..748385be51 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt @@ -3,6 +3,7 @@ [% USE Asset %] [% USE TablesSettings %] [%- USE KohaSpan -%] +[% USE KohaTimes %] [% PROCESS 'i18n.inc' %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] @@ -556,7 +557,16 @@
  • Opening hours: - [% IF library.library_hours.count > 0 # Existing library %] + [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %] + [% SET set_hours = 0 %] + [% IF library.library_hours.count > 0 %] + [% FOR i IN [0..6] %] + [% IF library.library_hours.as_list.$i.open_time != null || library.library_hours.as_list.$i.close_time != null %] + [% set_hours = 1 %] + [% END %] + [% END %] + [% END %] + [% IF set_hours > 0 # Existing library %] [% SET library_hours = library.library_hours.as_list %] @@ -575,10 +585,10 @@ [% PROCESS dayname day=d %] [% END %] @@ -757,7 +767,15 @@ { "data": function( row, type, val, meta ) { let result = ''; + let set_hours = 0; if ( row.library_hours.length > 0 ) { + for (let check_counter = 0; check_counter < 7; check_counter++) { + if ( row.library_hours[check_counter].open_time != null || row.library_hours[check_counter].close_time != null ) { + set_hours = 1; + } + } + } + if ( set_hours > 0 ) { const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ]; result = '
    - [% hr.open_time | html %] + [% IF hr.open_time != null %][% hr.open_time | $KohaTimes %][% END %] - [% hr.close_time | html %] + [% IF hr.close_time != null %][% hr.close_time | $KohaTimes %][% END %]
    '; @@ -766,8 +784,12 @@ const day = i % 7; // Wrap around the day using modulo operator result += ''; result += ''; - result += ''; - result += ''; + result += ''; + result += ''; result += ''; counter++; }
    DayOpen timeClose time
    '+daysOfWeek[day]+''+row.library_hours[day].open_time+''+row.library_hours[day].close_time+''; + result += row.library_hours[day].open_time != null ? $kohatime(row.library_hours[day].open_time): ''; + result += ''; + result += row.library_hours[day].close_time != null ? $kohatime(row.library_hours[day].close_time): ''; + result += '