Koha/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
Owen Leonard 72fc7babaa Bug 28938: Correct Flatpickr's default 12hr time formatting
This patch corrects Flatpickr's default 12 time formatting so that it
uses the formatting token "G" ("Hours, 2 digits with leading zeros")
instead of "h" ("Hours, 2 digits without leading zeros").

This will prevent incorrect times from being saved when the submitted
time is before 12.

- To test, apply the patch go to Administration -> System preferences.
- Set the TimeFormat system preference to "12 hour"
- Find an item which is checked out and renewable.
- Go to Circulation -> Renew and use the date picker to select a time <
  12, e.g. 9:00 AM
- Submit the barcode for renewal.
- Check the patron's account to see the due date of the renewed item: It
  should match the date and time you selected.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-09-02 08:48:24 +02:00

52 lines
2.4 KiB
PHP

[% USE Asset %]
[% USE Koha %]
[% USE raw %]
<!-- calendar.inc -->
[% FILTER collapse %]
<script>
var debug = "[% debug | html %]";
var dateformat_pref = "[% Koha.Preference('dateformat ') | html %]";
var dateformat_string = [% IF ( dateformat == "us" ) %]"mm/dd/yy"[% ELSIF ( dateformat == "metric" ) %]"dd/mm/yy"[% ELSIF ( dateformat == "dmydot" ) %]"dd.mm.yy"[% ELSE %]"yy-mm-dd"[% END %];
var flatpickr_dateformat_string = [% IF ( dateformat == "us" ) %]"m/d/Y"[% ELSIF ( dateformat == "metric" ) %]"d/m/Y"[% ELSIF ( dateformat == "dmydot" ) %]"d.m.Y"[% ELSE %]"Y-m-d"[% END %];
var sentmsg = 0;
var bidi = [% IF(bidi) %] true[% ELSE %] false[% END %];
var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
var flatpickr_timeformat_string = [% IF Koha.Preference('TimeFormat') == '12hr' %]"G:i K"[% ELSE %]"H:i"[% END %];
var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
</script>
<!-- / calendar.inc -->
[% Asset.js("js/calendar.js") | $raw %]
[% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
<script>
flatpickr.l10ns.default.weekdays = flatpickr_weekdays;
flatpickr.l10ns.default.months = flatpickr_months;
flatpickr.setDefaults({
allowInput: true,
dateFormat: flatpickr_dateformat_string,
nextArrow: '<i class="fa fa-fw fa-arrow-right"></i>',
prevArrow: '<i class="fa fa-fw fa-arrow-left"></i>',
time_24hr: flatpickr_timeformat,
locale: {
"firstDayOfWeek": calendarFirstDayOfWeek
},
onReady: function( selectedDates, dateStr, instance ){
/* When flatpickr instance is created, automatically append a "clear date" link */
$(instance.input)
.after( $("<a/>")
.attr("href","#")
.addClass("clear_date")
.on("click", function(e){
e.preventDefault();
instance.clear();
})
.addClass("fa fa-fw fa-remove")
.attr("aria-hidden", true)
.attr("aria-label", _("Clear date") )
);
},
onClose: function( selectedDates, dateText, instance) {
validate_date( selectedDates, instance );
},
});
</script>
[% END %]