From 03ea4bd0cc058bd3ca1c2e339371f45afc6c0244 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 25 Mar 2020 20:41:45 +0000 Subject: [PATCH] Bug 24980: Only add timezone if passed a date-time This patch prevents a timezone from being assigned to the js moment if the input string is only at the full-date and not date-time resolution To test: 1. Do not apply this patch 2. Set your system time zone to CET 3. Apply previous patch (It's just for test) 4. In your browser go to koha main page, open a console and type $date('2020-03-25', {tz: 'UTC'}) CHECK => you sould get '03/24/2020' (notice day is 24 instead of 25) 5. Apply this patch and reload the browser 6. repeat step 4 SUCCESS => now you get '03/25/2020' (day is correct) 7. Sing off Signed-off-by: Martin Renvoize Signed-off-by: Agustin Moyano Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- .../intranet-tmpl/prog/en/includes/js-date-format.inc | 2 +- .../opac-tmpl/bootstrap/en/includes/js-date-format.inc | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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 db93f9911a..64c8e8f2e2 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 @@ window.$date = function(value, options) { var tz = (options&&options.tz)||def_tz; var m = moment(value); - if(tz) m.tz(tz); + if((m.creationData().format !== 'YYYY-MM-DD')&&tz) m.tz(tz); var dateformat = (options&&options.dateformat)||def_date_format; var withtime = (options&&options.withtime)||false; diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc index 9381684bc6..21301d75bc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc @@ -24,10 +24,16 @@ return time_pattern; }; + /* + * A JS equivilent 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. + * Optionally accepts a dateformat parameter to allow override of the configured output format + * as well as a 'withtime' boolean denoting whether to include time or not in the output string. + */ window.$date = function(value, options) { var tz = (options&&options.tz)||def_tz; var m = moment(value); - if(tz) m.tz(tz); + if((m.creationData().format !== 'YYYY-MM-DD')&&tz) m.tz(tz); var dateformat = (options&&options.dateformat)||def_date_format; var withtime = (options&&options.withtime)||false; @@ -59,4 +65,4 @@ } })(); - \ No newline at end of file + -- 2.39.5