From 24fa8f68c82f517ce130a45a6d11b5a113347323 Mon Sep 17 00:00:00 2001 From: kb- Date: Sat, 12 May 2018 01:24:14 +0200 Subject: [PATCH 1/2] Give access to getDateString method Enables to customize the initial time by setting it in "readValue", in the options. readValue: function(element) { if (!element.value /* && element.getAttribute('data-type') === 'time' */) { // initial time if empty var d = new Date(); d.setHours(0, 0, 0); // Set hours, minutes and seconds return this.getDateString(d,true).replace(/:00$/,'');//today's date string, 00:00 time // return new Date().toTimeString().split(' ')[0]; // triggers default behavior } return element.value; // triggers default behavior } --- datePicker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datePicker.js b/datePicker.js index 522d359..6d2e435 100644 --- a/datePicker.js +++ b/datePicker.js @@ -181,7 +181,7 @@ function getDateTime(_this, options, element) { // revisit var value = options.readValue.call(_this, element), - date = getDateObject(value || getDateString(new Date(), true)), + date = getDateObject(value || _this.getDateString(new Date(), true)), timeFormat = element.getAttribute(options.timeFormatAttribute), hasAMPM = false, isPM = false; @@ -417,7 +417,7 @@ function addDays(_this, date, add, end) { date = _this.calendar.convertDateString(date, end); date.setDate(date.getDate() + add); - return getDateString(date); + return _this.getDateString(date); } function sortDates(date1, date2) { @@ -450,7 +450,7 @@ (date.AMPM ? ' ' + date.AMPM : '')) : '')); } - function getDateString(date, time) { + DatePicker.prototype.getDateString = function(date, time) { return date.getFullYear() + '-' + lZ(date.getMonth() + 1) + '-' + lZ(date.getDate()) + (time ? ' ' + date.toTimeString().split(' ')[0] : ''); } From a9ddc04b85d1b656c1370c1675109afe473291c3 Mon Sep 17 00:00:00 2001 From: kb- Date: Sat, 12 May 2018 02:45:11 +0200 Subject: [PATCH 2/2] Updated example, using getDateString method --- index.html | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 08dd35b..5c9a250 100644 --- a/index.html +++ b/index.html @@ -45,8 +45,8 @@

Demo


Range (name based): - - + +
Range with marked range: @@ -211,11 +211,13 @@

calendar.js

* @return {String} The value of the input field */ readValue: function(element) { - if (!element.value && element.getAttribute('data-type') === 'time') { // initial time if empty - return new Date().toTimeString().split(' ')[0]; // triggers default behavior - } - - return element.value; // triggers default behavior + if (!element.value /* && element.getAttribute('data-type') === 'time' */) { // initial time if empty + var d = new Date(); + d.setHours(0, 0, 0); // Set hours, minutes and seconds + return this.getDateString(d,true).replace(/:00$/,'');//today's date string, 00:00 time + // return new Date().toTimeString().split(' ')[0]; // triggers default behavior + } + return element.value; // triggers default behavior } }, /**