Set defaultDate for Pikaday to avoid "date jump" #246
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since we do not use/include moment.js in Torch (to
avoid adding more package dependencies and bloat),
Pikaday uses a function similar to the following to set
the default date if no
defaultDate
param is provided.In Torch, we set the input field value in the ISO-8601 format
of YYYY-MM-DD. The ISO-8601 spec should treat strings without
timezone specifiers as local time.
However, depending on the browser and ES version (ES5 vs ES6, etc...)
Date.parse will assume UTC. So, in the above, Date.parse is returning
UTC values, which then are passed to the
new Date
constructor whichreturns a date in the local timezone, and depending on what the local
timezone is, can result in the actual date display being off by 1 (in
either direction).
With this change, we now manually create a default date ourselves to
pass as the
defaultDate
argument to Pikaday to avoid any issue likethis in the future.
[Close #241]