-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Fix options passed to date-fns/parse #4474
Changes from all commits
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 |
---|---|---|
|
@@ -82,6 +82,8 @@ export function parseDate(value, dateFormat, locale, strictParsing, minDate) { | |
dateFormat.forEach((df) => { | ||
let tryParseDate = parse(value, df, new Date(), { | ||
locale: localeObject, | ||
useAdditionalWeekYearTokens: true, | ||
useAdditionalDayOfYearTokens: true, | ||
}); | ||
if (strictParsing) { | ||
strictParsingValueMatch = | ||
|
@@ -95,7 +97,11 @@ export function parseDate(value, dateFormat, locale, strictParsing, minDate) { | |
return parsedDate; | ||
} | ||
|
||
parsedDate = parse(value, dateFormat, new Date(), { locale: localeObject }); | ||
parsedDate = parse(value, dateFormat, new Date(), { | ||
locale: localeObject, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you'd like, and it's not a big deal, we could refactor this object into a const and use it everywhere 🔹 Code Reuse (Nice to have)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it's just that sometimes it gets joined with the locale, and sometimes not. We'd have to spread it everywhere ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
useAdditionalWeekYearTokens: true, | ||
useAdditionalDayOfYearTokens: true, | ||
}); | ||
|
||
if (strictParsing) { | ||
strictParsingValueMatch = | ||
|
@@ -117,7 +123,10 @@ export function parseDate(value, dateFormat, locale, strictParsing, minDate) { | |
.join(""); | ||
|
||
if (value.length > 0) { | ||
parsedDate = parse(value, dateFormat.slice(0, value.length), new Date()); | ||
parsedDate = parse(value, dateFormat.slice(0, value.length), new Date(), { | ||
useAdditionalWeekYearTokens: true, | ||
useAdditionalDayOfYearTokens: true, | ||
}); | ||
} | ||
|
||
if (!isValid(parsedDate)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pointing out the discrepancy with the option below that includes an
Of
inDayOfYear
and not this one, in case that is not intended.🔹 Style Consistency (Nice to have)
Jacques
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These come from date-fns, that's how the options are named.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Jacques