-
Notifications
You must be signed in to change notification settings - Fork 241
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: send date as string instead of epoch #6532
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6532 +/- ##
============================================
- Coverage 23.41% 23.40% -0.01%
Complexity 472 472
============================================
Files 249 249
Lines 11902 11901 -1
Branches 2282 2283 +1
============================================
- Hits 2787 2786 -1
Misses 8788 8788
Partials 327 327
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Now it seems to make sense. Time zones are ridiculously complicated.
I left a comment regarding the formatting in the frontend.
src/views/Appointments/Booking.vue
Outdated
const selectedDay = this.selectedDate.getFullYear().toString() + '-' + | ||
(this.selectedDate.getMonth() + 1).toString() + '-' + | ||
this.selectedDate.getDate().toString() |
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.
We need proper formatting here. Month and date might only have a single digit.
Please use the getYYYYMMDDFromDate(date)
from src/utils/date.js
which already implements formatting as YYYY-MM-DD
.
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.
import { getYYYYMMDDFromDate } from '../../utils/date.js'
// [...] further down
const selectedDay = getYYYYMMDDFromDate(this.selectedDate)
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.
Okay,
2024-1-1 or 2024-01-01 make no difference, its the same date.
getYYYYMMDDFromDate will not work. toISOString shifts the date to UTC which changes the date in some situations, already tried toISOString.
export function getYYYYMMDDFromDate(date) {
return new Date(date.getTime() - (date.getTimezoneOffset() * 60000))
.toISOString()
.split('T')[0]
}
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, that is why Georg implemented it in a way that reverts the shift to UTC (from the browser's local time zone). See date.getTime() - (date.getTimezoneOffset() * 60000)
I tested it with a fake time zone in Chrome and it should work correctly.
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.
Okay, I'll change it and try it.
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, I don't trust the calculation in getYYYYMMDDFromDate
Tested with:
-
Value In
Wed Nov 27 2024 14:44:54 GMT-0500 (Eastern Standard Time) -
Value produced by "new Date(date.getTime() - date.getTimezoneOffset() * 60000)"
Wed Nov 27 2024 09:44:54 GMT-0500 (Eastern Standard Time)
As you can see it shifted the time by 5 hours. This would have the effect of shifting the date, if the input value time was less then the offset.
E.g.
Input
Wed Nov 27 2024 2:00:00 GMT-0500 (Eastern Standard Time)
Result
Wed Nov 26 2024 21:00:00 GMT-0500 (Eastern Standard Time)
Then toISOString produces this
2024-11-27T14:44:54.790Z
The end result seems correct in my browser and time zone but will this be correct for every time zone and browser. IDK
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 that it is confusing. The thing is, that JavaScript's Date is not time zone aware. It always converts to the local time zone, regardless of which time zone you pass to the constructor.
We have unit tests in place to ensure that this implementation works and it is used throughout Calendar.
If it breaks we can fix it. The important thing is that we have one central implementation and not many copied across the code base because this is way harder to maintain.
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.
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.
But yeah, let's not get pedantic over 3 lines of code.
Let's not get pedantic over 3 lines of code.
@GVodyanov could you give this a test with the instructions provided? :) |
Do you have an "all day event" on that Tuesday? That would cause the slots to be filtered out as a conflict during that time. |
I'm dumb |
🤣 don't worry, I did the same thing |
Signed-off-by: SebastianKrupinski <[email protected]>
0b07541
to
91d787c
Compare
/backport to stable5.0 |
Resolves: #6528
Testing Recommendation