Closed chikakow closed 3 years ago
Hi @chikakow Thanks for pointing out this issue.
I was trying to make luxon
compatible to Date.getDay which returns 0
for Sunday.
It seems that the fix needs to consider that for luxon, the weekday
states
Get the day of the week. 1 is Monday and 7 is Sunday
also the NativeDateAdapter
uses 0 = Sunday, 1 = Monday
for the getFirstDayOfWeek
so the fix would look like:
getDayOfWeek(date: DateTime): number {
return date.weekday === 7 ? 0 : date.weekday;
}
what do you think?
Yes that code works.
The previous code
date.weekday - 1
was actually creating off by 1 problem with the picker. May 22nd is Saturday
With the new code you provided above, It falls into Saturday.
Great news @chikakow you can try @matheo/datepicker@11.2.16
which includes this fix :)
Describe the bug
I'm using matheo Luxon Date Adapter for my app. I am using Luxon in my entire app. I had to copy the code from the source code and swapped out with unofficial Google LuxonDateAdapeter. I realized that Google version and Matheo version is almost identical except Matheo version has conversion for time for obvious reason. However, I found one more difference which is not related to time. getDayOfWeek is modified to negate 1 from luxon default weekday. The default if Sunday returns 7, Matheo version return 6. When I got the code from Google, I also got unit test to go with it too. Then now I swapped with Matheo version, this getDayOfWeek unit test is failing. To fix this unit test, I can just remove negation of 1 but is there a specific reason why Matheo version is negating 1?
Minimal Reproduction
Find the Google version LuxonAdapter from this link https://github.com/andreialecu/ngx-material-luxon/blob/main/projects/ngx-material-luxon/src/lib/adapter/luxon-date-adapter.ts
And Find Unit Test for the Google Version LuxonDateAdapter from this link https://github.com/andreialecu/ngx-material-luxon/blob/main/projects/ngx-material-luxon/src/lib/adapter/luxon-date-adapter.spec.ts
Use Matheo Verion LuxonDateAdapeter and run the unit tests
Expected behavior
All test should still pass.
Screenshots
Your Environment
Angular Version: