Skip to content

Commit

Permalink
fix(date-picker): let Flatpickr parse date instead of doing it with n…
Browse files Browse the repository at this point in the history
…ew Date() (carbon-design-system#431)

JavaScript Date constructor does not have proper i18n support when a string is given.
You'll see a very ambiguous spec at: https://www.ecma-international.org/ecma-262/6.0/#sec-date.parse
In the particular case of carbon-design-system#396, `new Date()` seems to think `Y-m-d` format as an ISO8601 UTC-based string,
whereas `Y/m/d` seems to be treated as a locale-specific, local-timezone-based string.
It ends up with producing a date object for the former case, that is of six hours before the clock for users in Austin,
and thus one day off for the date part.

Fixes carbon-design-system#396.
  • Loading branch information
asudoh authored and marijohannessen committed Nov 14, 2017
1 parent 54f7110 commit c8752b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/date-picker/date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class DatePicker extends mixin(createComponent, initComponentBySearch) {
_addInputLogic = input => {
const inputField = input;
inputField.addEventListener('change', () => {
const inputDate = this.calendar.parseDate(new Date(inputField.value));
const inputDate = this.calendar.parseDate(inputField.value);
if (!isNaN(inputDate.valueOf())) {
this.calendar.setDate(inputDate);
}
Expand Down

0 comments on commit c8752b6

Please sign in to comment.