Skip to content

Commit 0c24f6b

Browse files
committed
fix(DatePicker, DateRangePicker): prevent set 1970-01-01T00:00:00.000Z date when initial dates are not set when using the cancel() method
1 parent 325787b commit 0c24f6b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

js/src/date-range-picker.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ class DateRangePicker extends BaseComponent {
232232
return
233233
}
234234

235-
this._initialStartDate = new Date(this._startDate)
236-
this._initialEndDate = new Date(this._endDate)
235+
this._initialStartDate = this._startDate ? new Date(this._startDate) : null
236+
this._initialEndDate = this._endDate ? new Date(this._endDate) : null
237237

238238
EventHandler.trigger(this._element, EVENT_SHOW)
239239
this._element.classList.add(CLASS_NAME_SHOW)
@@ -274,15 +274,19 @@ class DateRangePicker extends BaseComponent {
274274
}
275275

276276
cancel() {
277-
this._changeStartDate(this._initialStartDate)
277+
this.hide()
278278

279-
if (this._config.range) {
280-
this._changeEndDate(this._initialEndDate)
279+
if (this._initialStartDate) {
280+
this._changeStartDate(this._initialStartDate)
281281
}
282282

283-
this.hide()
283+
if (this._config.range && this._initialEndDate) {
284+
this._changeEndDate(this._initialEndDate)
285+
}
284286

285-
this._calendar.update(this._getCalendarConfig)
287+
if (this._initialStartDate || this._initialEndDate) {
288+
this._calendar.update(this._getCalendarConfig)
289+
}
286290
}
287291

288292
clear() {

js/src/util/calendar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const getTrailingDays = (year, month, leadingDays, monthDays) => {
268268
* @returns The ISO week number.
269269
*/
270270
export const getWeekNumber = date => {
271-
const tempDate = new Date(date.getTime())
271+
const tempDate = new Date(date)
272272
tempDate.setHours(0, 0, 0, 0)
273273

274274
// Thursday in current week decides the year

0 commit comments

Comments
 (0)