From 6925b943b4899ac67ec412618223443e0a870353 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Tue, 22 Oct 2019 18:28:02 +0200 Subject: [PATCH] Fixed datepicker.js --- .../fanstatic/daterangepicker-module.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ckanext/datesearch/fanstatic/daterangepicker-module.js b/ckanext/datesearch/fanstatic/daterangepicker-module.js index b1c6fdf..0e5c76c 100644 --- a/ckanext/datesearch/fanstatic/daterangepicker-module.js +++ b/ckanext/datesearch/fanstatic/daterangepicker-module.js @@ -9,16 +9,18 @@ this.ckan.module('daterangepicker-module', function ($, _) { }; // Pick out relevant parameters - param_start = $.urlParam('ext_startdate'); - param_end = $.urlParam('ext_enddate'); + var param_start = $.urlParam('ext_startdate'); + var param_end = $.urlParam('ext_enddate'); + + var fs = 'YYYY-MM-DD'; // Populate the datepicker and hidden fields if (param_start) { - $('#datepicker #start').val(moment.utc(param_start).format()); + $('#datepicker #start').val(moment.utc(param_start).format(fs)); $('#ext_startdate').val(param_start); } if (param_end) { - $('#datepicker #end').val(moment.utc(param_end).format()); + $('#datepicker #end').val(moment.utc(param_end).format(fs)); $('#ext_enddate').val(param_end); } @@ -49,12 +51,13 @@ this.ckan.module('daterangepicker-module', function ($, _) { // Format the start and end dates into strings in a date format that Solr understands. var v = moment(ev.date); var fs = 'YYYY-MM-DDTHH:mm:ss'; + var dateFormatted = v.format(fs) + 'Z'; switch (ev.target.name) { case 'start': // Set the value of the hidden to the chosen start date. if (ev.date) { - $('#ext_startdate').val(v.format(fs) + 'Z'); + $('#ext_startdate').val(dateFormatted); } else { $('#ext_startdate').val(''); } @@ -62,7 +65,7 @@ this.ckan.module('daterangepicker-module', function ($, _) { case 'end': // Set the value of the hidden to the chosen end date. if (ev.date) { - $('#ext_enddate').val(v.add('y', 1).subtract('s', 1).format(fs) + 'Z'); + $('#ext_enddate').val(v.add('d', 1).subtract('s', 1).format(fs) + 'Z'); } else { $('#ext_enddate').val(''); }