set start/end date after setting date if they land on the same day, closes #2335

This commit is contained in:
Carson
2019-08-27 10:30:38 -05:00
parent 1a8b36f06d
commit 896a20d76d
2 changed files with 45 additions and 21 deletions

View File

@@ -139,19 +139,31 @@ $.extend(dateInputBinding, {
return;
if (date === null) {
$(el).bsDatepicker('setStartDate', null);
return;
}
} else {
date = this._newDate(date);
date = this._UTCDateAsLocal(date);
if (!isNaN(date)) {
// Workaround for https://github.com/eternicode/bootstrap-datepicker/issues/2010
// If the start date when there's a two-digit year format, it will set
// the date value to null. So we'll save the value, set the start
// date, and the restore the value.
var curValue = $(el).bsDatepicker('getUTCDate');
$(el).bsDatepicker('setStartDate', date);
$(el).bsDatepicker('setUTCDate', curValue);
}
date = this._newDate(date);
date = this._UTCDateAsLocal(date);
if (isNaN(date))
return;
// Workaround for https://github.com/eternicode/bootstrap-datepicker/issues/2010
// If the start date when there's a two-digit year format, it will set
// the date value to null. So we'll save the value, set the start
// date, and the restore the value.
var curValue = $(el).bsDatepicker('getUTCDate');
$(el).bsDatepicker('setStartDate', date);
$(el).bsDatepicker('setUTCDate', curValue);
// Workaround for https://github.com/rstudio/shiny/issues/2335
// We only set the start date *after* the value in this special
// case so we don't effect the intended behavior of having a blank
// value when it falls outside the start date
if (typeof date.toDateString !== 'function') return;
if (typeof curValue.toDateString !== 'function') return;
if (date.toDateString() === curValue.toDateString()) {
$(el).bsDatepicker('setStartDate', null);
$(el).bsDatepicker('setUTCDate', curValue);
$(el).bsDatepicker('setStartDate', date);
}
},
// Given an unambiguous date string or a Date object, set the max (end) date
@@ -161,16 +173,26 @@ $.extend(dateInputBinding, {
return;
if (date === null) {
$(el).bsDatepicker('setEndDate', null);
return;
}
} else {
date = this._newDate(date);
date = this._UTCDateAsLocal(date);
if (!isNaN(date)) {
// Workaround for same issue as in _setMin.
var curValue = $(el).bsDatepicker('getUTCDate');
$(el).bsDatepicker('setEndDate', date);
$(el).bsDatepicker('setUTCDate', curValue);
}
date = this._newDate(date);
date = this._UTCDateAsLocal(date);
if (isNaN(date))
return;
// Workaround for same issue as in _setMin.
var curValue = $(el).bsDatepicker('getUTCDate');
$(el).bsDatepicker('setEndDate', date);
$(el).bsDatepicker('setUTCDate', curValue);
// Workaround for same issue as in _setMin.
if (typeof date.toDateString !== 'function') return;
if (typeof curValue.toDateString !== 'function') return;
if (date.toDateString() === curValue.toDateString()) {
$(el).bsDatepicker('setEndDate', null);
$(el).bsDatepicker('setUTCDate', curValue);
$(el).bsDatepicker('setEndDate', date);
}
},
// Given a date string of format yyyy-mm-dd, return a Date object with