-
Notifications
You must be signed in to change notification settings - Fork 299
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 miss matched timezones in claim form #2651
Conversation
1424f02
to
498f522
Compare
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.
The sdk assumes we are submitting local time for Amsterdam that is UTC+02:00 so that is converted in the sdk to UTC+00:00 before POST`in to the sever (simply it minuses 2 hours)
There is nothing in the js sdk that is related to date handling/transformation. The problem here is that yup
's date casts dates according to local time. See https://codesandbox.io/s/competent-oskar-od6qn
I guess using .mixed()
with custom validation should solve the issue.
pkg/webui/lib/to-input-date.js
Outdated
@@ -0,0 +1,19 @@ | |||
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. |
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.
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V. | |
// Copyright © 2020 The Things Network Foundation, The Things Industries B.V. |
pkg/webui/lib/to-input-date.js
Outdated
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
export default function(date) { |
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.
jsdoc and some tests would be very helpful here
Yup dates are outputted in local time yes but if you log
then the payload for the api call is
So the sdk is setting the time to GMT+0000 purposely or not |
Once again, the js sdk has nothing to do with dates. There is no specific code to deal with dates, transform or anything else.
Try logging
|
b129e3c
to
2874fc3
Compare
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.
I get
claim_authentication_code: {
value: "...",
valid_from: "2020-06-23T21:00:00Z"
}
when selecting 24/06/2020
in the date picker. Notice -3 hrs since Im in GMT+3
So if we are setting the time in the browser as the date at the beginning of the day ( 00:00 ) of your local time, that would be saved in the DB as GMT+0000 so that would 21:00 of the previous day. On retrieving this the browser then converts this to local time and displays the correct date. I think maybe the question here should be that, should the time be shown as local time in the browser and stored as GMT+0000 or Should it always be GMT+0000 I would go with browser being local time @bafonins @kschiffer what do you think? |
Indeed, you are right.
From the user perspective, I would assume that date is set based on my timezone. I dont think we should force the users to set dates based on GMT+0, at least thats not very common for modern UIs. |
2874fc3
to
06d5631
Compare
06d5631
to
8d52c55
Compare
@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
|
|||
### Fixed | |||
|
|||
- Timezones issue in claim auth code form, causing time to reverse on submission |
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.
- Timezones issue in claim auth code form, causing time to reverse on submission | |
- Timezones issue in claim authentication code form, causing time to reverse on submission. |
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.
So for my understanding, the claim api expects a simple date string e.g. (`2020-06-10`) and uses the local timezone of the server?
If so, then that means that there can be discrepancies between the timezone of the client and the server, while the user will (rightfully) assume that his own timezone is going to be used. So ideally, we should display the underlying server timezone that is going to be used for this date.
That means that we need a way to retrieve the timezone of the server. @htdvisser do we already have something to achieve this?
It's edge casy enough that I'm ok with merging this as it is for now, but still this needs to be addressed eventually.
All our APIs always use UTC. The format is |
So @mjamescompton, please add a field-description that informs the user that the date is UTC +0 based. |
Why so? It is a common practice to store dates on servers/databases as UTC+0 timestamps for simplicity and for the apps that do not heavily depend on planning, e.g. event scheduling apps. I dont think we should force the users to think about this (at least in the console, for CLI is a different story), especially when our customers can be distributed around the globe. Here is an example:
For all, user A,B and the server date and time are set properly. The only problem I can imagine happening is with DST, as different browsers might process this differently from one another. This can solved with date-fns which can also simplify dealing with dates in other parts of the app. Moreover, if we decide to UTC+0 here, we introduce another inconsistency as we use users local time in many places across the Console, e.g. As mentioned above, the CLI is a different story and I would expect the developers to check what is the format in the docs, we cannot really guide anyone there. |
I agree with everything you said. I had a misconception there. I thought the server would only receive a simple date-string |
I see. @mjamescompton fine to merge this. We can still change it later if we find it more useful. |
e1d66f4
to
c9816f9
Compare
@mjamescompton can you merge this PR? otherwise please add the |
c9816f9
to
d3b9dab
Compare
Summary
Closes #2650
Changes
.toISOString()
on date object and replace with function that returns formatted local timeTesting
Fill in form and make sure everything stays the same on multiple submissions of the same data.
Notes for Reviewers
The sdk assumes we are submitting local time for Amsterdam that is UTC+02:00 so that is converted in the sdk to UTC+00:00 before POST`in to the sever (simply it minuses 2 hours)
so 25/4/2020 00:00 is converted to 24/4/2020 10:00
When the time is return to the form from the server it receives 24/4/2020 10:00 which should be converted to local time but instead is displayed as is.
Using
.toISOString()
return the the date/time in UTC+00:00 and the time is removed.Using the date object as is returns local time date/time as UTC+02:00.
Checklist
README.md
. The target branch is set tomaster
if the changes are fully compatible with existing API, database, configuration and CLI.CHANGELOG.md
.CONTRIBUTING.md
, there are no fixup commits left.