-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[pickers] Avoid relying on locale in Luxon isWithinRange
method
#11936
Conversation
Deploy preview: https://deploy-preview-11936--material-ui-x.netlify.app/ |
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!
|
||
describe('isWithinRange functionality', () => { | ||
const adapter = new AdapterLuxon({ locale: 'en-US' }); | ||
it('should be equal with values in different locale', () => { |
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.
If possible, it would be great to move the test inside describeGregorianAdapter
(there is a describe
for isWithinRange
).
That way we make sure that all adapters are coherent on this behavior.
We have a adapterFr
object that is using the french locale so we should be able to use it to create the two dates and then use adapter
to run isWithingRange
with an en-US
locale.
If I'm missing something and there is a technical limitation preventing us from doing it, it's of course not a deal breaker 👌
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.
Thanks for a great suggestion! 🙏
Moved the test and tests it's reliability. 😉
@@ -324,8 +324,8 @@ export class AdapterLuxon implements MuiPickersAdapter<DateTime, string> { | |||
|
|||
public isWithinRange = (value: DateTime, [start, end]: [DateTime, DateTime]) => { | |||
return ( | |||
value.equals(start) || | |||
value.equals(end) || | |||
this.isEqual(value, start) || |
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.
The fix makes a lot of sense, thanks for taking care ok it 👌
Fixes #11622
We used Luxon API for comparing equality, but it also includes some metadata in comparison (like locale the date was created it).
With this change, we are only going to compare the difference in time.