Skip to content
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] Add support for timezones on the adapters #9068

Merged
merged 7 commits into from
May 26, 2023

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented May 22, 2023

Extracted from #8261
Part of #8484

This PR focuses on the adapters and should not include any behavior changes on the pickers themselves.

  • Add 3 new methods dateWithTimezone (will replace date in v7), getTimezone and setTimezone
  • Add tests

@flaviendelangle flaviendelangle added the component: pickers This is the name of the generic UI component, not the React module! label May 22, 2023
@flaviendelangle flaviendelangle self-assigned this May 22, 2023
@mui-bot
Copy link

mui-bot commented May 22, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-9068--material-ui-x.netlify.app/

Updated pages

No updates.

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 846.2 1,493.6 846.2 1,117.38 265.605
Sort 100k rows ms 796.3 1,436.8 1,389.1 1,197.4 229.782
Select 100k rows ms 216.3 383.2 344.1 324.96 57.485
Deselect 100k rows ms 159.2 288.8 246.7 235.42 50.906

Generated by 🚫 dangerJS against 5aa171e

@flaviendelangle flaviendelangle force-pushed the timezone-adapters branch 2 times, most recently from c4755a2 to 7124db5 Compare May 22, 2023 08:33
};

public isWithinRange = (value: Dayjs, [start, end]: [Dayjs, Dayjs]) => {
return value.isBetween(start, end, null, '[]');
return value >= start && value <= end;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the power of isBefore and isAfter because we are not passing any unit.
The main advantage of this change is that isBetween / isAfter are very slow on dayjs with the timezone plugin, so I'm trying to use them as little as possible

@@ -259,36 +296,42 @@ export class AdapterLuxon implements MuiPickersAdapter<DateTime, string> {
return false;
}

return this.date(value)!.equals(this.date(comparing)!);
return +this.date(value)! === +this.date(comparing)!;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically speaking, this is a breaking change for the Luxon adapter, because now isEqual returns true if you have 2 dates with the same timestamp but a different zone.

I think we can consider it to be a bug fix because the other adapters are not working the same way and are already based on the timestamp.

@flaviendelangle flaviendelangle marked this pull request as ready for review May 22, 2023 11:15
Comment on lines +322 to +323
// Both dates below have the same timestamp, but they are not in the same year when represented in their respective timezone.
// The adapter should still consider that they are in the same year.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is somewhat disturbing. Would it be true to say that the isSameYear relies on the timezone of the first/second date provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be true to say that the isSameYear relies on the timezone of the first/second date provided?

Yes, all the isSameXXX isAfterXXX and isBeforeXXX are applied on the timezone of the 1st param.
isSameYear answers the question "for any A and B, is A and B in the same year when displayed in the timezone of A"

Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good for me.

I don't have a strong opinion is isAfterDay should consider the TZ of the first or second argument. But it could be precise in the method comment:

- Check if the day of the reference date is after the day of the second date.
+ Check if the timestamp of the reference date is after the day of the second date (using the TZ of the second date).

Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massive and insanely important greatly executed feature! 🚀 💯

Some minor nitpicks and a general question regarding the variable name correctness/clarity. 😉

@flaviendelangle flaviendelangle merged commit 4685e70 into mui:master May 26, 2023
@flaviendelangle flaviendelangle deleted the timezone-adapters branch May 26, 2023 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants