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
app: fix wallet birthday is UTC date #2236
Conversation
74fe56d
to
a538357
Compare
Seems to be working as expected, but I'm going to try again in a couple hours when it's tomorrow in GMT. |
No longer getting a future date when it's tomorrow in GMT but not locally. Wallet backend gets the right date as well, logged as |
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.
Yeah, sorta intended. @martonp would probably be most familiar with the logic, but that may 27, 2022 day is the default birthday under certain conditions. Perhaps the workflow you described of switching wallet types evades the logic that detects the "is seeded" check that should use a more recent time. |
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.
LGTM
When using a <input type='date'> element, it is tricky to get the time zone correct when using the value, valueAsNumber, and valueAsDate fields. This is because the browser will always display the date as UTC, regardless of how you have set valueAsDate. Also, when getting the date out with new Date(input.value), where the value is yyyy-mm-dd, the Date parses as in UTC. When the user is interacting with the input element, they are thinking in local time. However, unless we offset the time that we set, it can show an incorrect date. This change sets the value date string manually to the local date. We could also offsets the Date that we assign to valueAsDate so that it will show a local date, or similarly with valueAsNumber, but this is harder to follow and we do not benefit from finer precision that simply 12am of the current day. When reading the selected date back into javascript, we also have to interpret it as a local date string. We do this by forcing the Date constructor to interpret the date as local by appending "T00:00" to the date string from input.value. We also must use this trick when reading the min and max date strings. We could instead use valueAsDate and manually shift in the opposite direction as when we set it, but this seems better.
a538357
to
4a0abeb
Compare
Resolves #2192
When using a
<input type='date'>
element, it is tricky to get the time zone correct when using thevalue
,valueAsNumber
, andvalueAsDate
fields. This is because the browser will always display the date as UTC, regardless of how you have setvalueAsDate
. Also, when getting the date out withnew Date(input.value)
, where the value isyyyy-mm-dd
, theDate
parses as in UTC (12am UTC instead of local).When the user is interacting with the input element, they are thinking in local time. However, unless we offset the time that we set, it can show an incorrect date. This change sets the
value
date string manually to the local date. We could also offset theDate
that we assign tovalueAsDate
so that it will show a local date, or similarly withvalueAsNumber
, but this is harder to follow and we do not benefit from finer precision than simply 12am of the current day.When reading the selected date back into javascript, we also have to interpret it as a local date string. We do this by forcing the
Date
constructor to interpret the date as local by appending"T00:00"
to the date string frominput.value
. We also must use this trick when reading themin
andmax
date strings. We could instead usevalueAsDate
and manually shift in the opposite direction as when we set it, but this seems better.See https://dev.to/mendyberger/input-and-js-dates-2lhc for a better explanation