Bugzilla – Attachment 144680 Details for
Bug 31149
Use dayjs to parse dates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31149: Use dayjs to parse dates
Bug-31149-Use-dayjs-to-parse-dates.patch (text/plain), 3.76 KB, created by
Paul Derscheid
on 2022-12-16 14:13:20 UTC
(
hide
)
Description:
Bug 31149: Use dayjs to parse dates
Filename:
MIME Type:
Creator:
Paul Derscheid
Created:
2022-12-16 14:13:20 UTC
Size:
3.76 KB
patch
obsolete
>From e55b0f62987e6ff595495bc86ddf7e3081329ed0 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 13 Jul 2022 09:06:32 +0200 >Subject: [PATCH] Bug 31149: Use dayjs to parse dates > >We can use the isValid's dayjs function instead of our own parsing >functions. > >Test plan: >Confirm that you cannot enter an invalid date when using a date picker widget. > >Works as expected. > >Signed-off-by: LMSCloudPaulD <paul.derscheid@lmscloud.de> >--- > .../prog/en/includes/calendar.inc | 1 + > koha-tmpl/intranet-tmpl/prog/js/calendar.js | 37 +++---------------- > 2 files changed, 6 insertions(+), 32 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >index 43e57168ba..ff1f6a8a34 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc >@@ -27,6 +27,7 @@ > var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %]; > </script> > <!-- / calendar.inc --> >+[% Asset.js("lib/dayjs/dayjs.min.js") | $raw %] > [% Asset.js("js/calendar.js") | $raw %] > [% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %] > [% Asset.js("lib/flatpickr/shortcut-buttons-flatpickr.min.js") | $raw %] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/calendar.js b/koha-tmpl/intranet-tmpl/prog/js/calendar.js >index 81561cc42d..c8247513c0 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/calendar.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/calendar.js >@@ -5,29 +5,8 @@ if (debug > 1) { > alert("dateformat: " + dateformat_pref + "\ndebug is on (level " + debug + ")"); > } > >-function is_valid_date(date) { >- // An empty string is considered as a valid date for convenient reasons. >- if (date === '') return 1; >- var dateformat = flatpickr_dateformat_string; >- if (dateformat == 'us') { >- if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; >- dateformat = 'm/d/Y'; >- } else if (dateformat == 'metric') { >- if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0; >- dateformat = 'd/m/Y'; >- } else if (dateformat == 'iso') { >- if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0; >- dateformat = 'Y-m-d'; >- } else if (dateformat == 'dmydot') { >- if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0; >- dateformat = 'd.m.Y'; >- } >- try { >- flatpickr.parseDate(date, dateformat); >- } catch (e) { >- return 0; >- } >- return 1; >+function is_valid_date(dateText) { >+ return dayjs(dateText, get_dateformat_str(dateformat_pref).toUpperCase(), true ).isValid(); > } > > function get_dateformat_str(dateformat) { >@@ -58,20 +37,14 @@ function Date_from_syspref(dstring) { > sentmsg++; > alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n")); > } >- if (dateformat_pref === "iso") { >- return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d) >- } else if (dateformat_pref === "us") { >- return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d) >- } else if (dateformat_pref === "metric") { >- return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d) >- } else if (dateformat_pref === "dmydot") { >- return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d) >- } else { >+ let d = dayjs(dstring, get_dateformat_str(dateformat_pref).toUpperCase(), true); >+ if ( !d.isValid() ) { > if (debug > 0) { > alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref); > } > return 0; > } >+ return d.toDate(); > } > > function DateTime_from_syspref(date_time) { >-- >2.37.1 (Apple Git-137.1)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 31149
:
137680
|
144680
|
144733