Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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] : '');
}
Expand Down
16 changes: 9 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ <h2>Demo</h2>
<input class="date date-1" value="" data-from="theFlight" placeholder="YYYY-MM-DD HH:MM APM" data-timeformat="HH:MM PM" />
<input class="date date-1" value="" data-to="theFlight" placeholder="YYYY-MM-DD HH:MM APM" data-timeformat="HH:MM PM" />
<br><span>Range (name based): </span>
<input class="date date-1" value="" name="flight-from" data-from="flight-to" placeholder="YYYY-MM-DD" />
<input class="date date-1" value="" name="flight-to" data-to="flight-from" placeholder="YYYY-MM-DD" />
<input class="date date-1" value="" name="flight-from" data-from="flight-to" placeholder="YYYY-MM-DD HH:MM" />
<input class="date date-1" value="" name="flight-to" data-to="flight-from" placeholder="YYYY-MM-DD HH:MM" />
<br><span>Range with marked range: </span>
<input class="date date-11" value="" name="flight-from-1" data-from="flight-to-1" placeholder="YYYY-MM-DD" />
<input class="date date-11" value="" name="flight-to-1" data-to="flight-from-1" placeholder="YYYY-MM-DD" />
Expand Down Expand Up @@ -211,11 +211,13 @@ <h2>calendar.js</h2>
* @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
}
},
/**
Expand Down