-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: Inconsistent/broken behavior in parseDate
#5036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
883353c
16b9c94
6dfbbe6
e4ed031
e80b0e7
63e2239
053b403
e9fe0bf
9eee52d
0ba1294
6ccd449
1152459
c4323b3
b34bfb2
3e1733e
4068262
39d255a
88a9dd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ import React, { Component, cloneElement } from "react"; | |
import Calendar from "./calendar"; | ||
import CalendarIcon from "./calendar_icon"; | ||
import { | ||
set, | ||
newDate, | ||
isDate, | ||
isBefore, | ||
|
@@ -587,13 +586,8 @@ export default class DatePicker extends Component< | |
lastPreSelectChange: PRESELECT_CHANGE_VIA_INPUT, | ||
}); | ||
|
||
const { | ||
dateFormat = DatePicker.defaultProps.dateFormat, | ||
strictParsing = DatePicker.defaultProps.strictParsing, | ||
selectsRange, | ||
startDate, | ||
endDate, | ||
} = this.props; | ||
const { dateFormat, strictParsing, selectsRange, startDate, endDate } = | ||
this.props; | ||
|
||
const value = | ||
event?.target instanceof HTMLInputElement ? event.target.value : ""; | ||
|
@@ -604,15 +598,15 @@ export default class DatePicker extends Component< | |
.map((val) => val.trim()); | ||
const startDateNew = parseDate( | ||
valueStart ?? "", | ||
dateFormat, | ||
dateFormat!, | ||
|
||
this.props.locale, | ||
strictParsing, | ||
strictParsing!, | ||
); | ||
const endDateNew = parseDate( | ||
valueEnd ?? "", | ||
dateFormat, | ||
dateFormat!, | ||
this.props.locale, | ||
strictParsing, | ||
strictParsing!, | ||
); | ||
const startChanged = startDate?.getTime() !== startDateNew?.getTime(); | ||
const endChanged = endDate?.getTime() !== endDateNew?.getTime(); | ||
|
@@ -631,28 +625,14 @@ export default class DatePicker extends Component< | |
this.props.onChange?.([startDateNew, endDateNew], event); | ||
} else { | ||
// not selectsRange | ||
let date = parseDate( | ||
const date = parseDate( | ||
value, | ||
dateFormat, | ||
dateFormat!, | ||
this.props.locale, | ||
strictParsing, | ||
this.props.minDate, | ||
strictParsing!, | ||
this.props.selected ?? undefined, | ||
); | ||
|
||
// Use date from `selected` prop when manipulating only time for input value | ||
if ( | ||
this.props.showTimeSelectOnly && | ||
this.props.selected && | ||
date && | ||
!isSameDay(date, this.props.selected) | ||
) { | ||
date = set(this.props.selected, { | ||
hours: getHours(date), | ||
minutes: getMinutes(date), | ||
seconds: getSeconds(date), | ||
}); | ||
} | ||
|
||
// Update selection if either (1) date was successfully parsed, or (2) input field is empty | ||
if (date || !value) { | ||
this.setSelected(date, event, true); | ||
|
Uh oh!
There was an error while loading. Please reload this page.