From 89791181bb8ba5e3248cb19fd6dba09a632309ab Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 13 Feb 2020 12:25:31 +0000 Subject: [PATCH] Bug 24650: Convert ISO datetimes to syspref dates This patch adds a function 'ISO_to_syspref' that accepts an ISO8601 / RFC3339 formatted timestamp, as returned from the API for datetime DB columns, and returns a string formatted according to the 'dateformat' syspref, optionally including the time Test plan: - Apply the patch - Load a page that uses calendar.inc, for example a patron's loan list in the staff interface - In the JS console, type the following and notice the printed date is in the format according to the syspref: var dt = new Date; console.log(ISO_to_syspref(dt.toISOString())); - In the JS console, type the following and notice the printed date is in the format according to the syspref, and includes the time: console.log(ISO_to_syspref(dt.toISOString(), true)); Signed-off-by: David Nind --- koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc index 1cd41e2961..a41ccf7d0e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc @@ -99,6 +99,16 @@ function DateTime_from_syspref(date_time) { return datetime; } +function ISO_to_syspref(date_time, include_time) { + var dt = new Date(Date.parse(date_time)); + var dateFormat = get_dateformat_str('[% Koha.Preference('dateformat') | html %]'); + dateFormat = dateFormat.replace('yyyy', 'yy'); + var ret = $.datepicker.formatDate(dateFormat, dt); + if (include_time) { + ret += ' ' + dt.getHours() + ':' + dt.getMinutes(); + } + return ret; +} /* Instead of including multiple localization files as you would normally see with jQueryUI we expose the localization strings in the default configuration */ -- 2.11.0