Skip to content
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

Set defaultDate for Pikaday to avoid "date jump" #246

Merged
merged 1 commit into from
Jun 30, 2021

Conversation

cpjolicoeur
Copy link
Member

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.

defaultDate = new Date(Date.parse(field.value))

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 which
returns 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 like
this in the future.

[Close #241]

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.

    defaultDate = new Date(Date.parse(field.value))

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 which
returns 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 like
this in the future.

[Close #241]
@cpjolicoeur cpjolicoeur merged commit 39adc79 into master Jun 30, 2021
@cpjolicoeur cpjolicoeur deleted the cpj/bug_issue_241 branch June 30, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date filters are altered after applying filter
1 participant