-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[data grid] Date filtering with negative timezone offset #12785
Comments
If we are talking about native date inputs, that is in total control of the browser and yes, if I'm not mistaken, it will always use the host timezone. 🤔
@elawad How do you do that? 🤔 |
Hi I’ll provide a sample shortly. But it’s the same as the demo above. You can change your timezone in your mac/pc settings. I’m already on EST, but I was able to test other time zones as well. |
Example: https://codesandbox.io/p/sandbox/recursing-scooby-5jfdzx Issue when using Was working in v6. Might be related to this release, where Filter now uses a Date object. DataGrid-Filter-Date-EST-Bug.mov |
That actually makes sense. The dates are probably rendered with values that represent the local timezone ( @LukasTy can you test this? I could also test this later today (I need to update MacOS anyways). |
Hey ... I just did some digging and the problem is as I suspected: We do perform some calculation with the timezoneOffset and that backfired a bit. Here is a diff with a potential fix --- a/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputDate.tsx
+++ b/packages/x-data-grid/src/components/panel/filterPanel/GridFilterInputDate.tsx
@@ -29,14 +29,14 @@ function convertFilterItemValueToInputValue(
if (Number.isNaN(dateCopy.getTime())) {
return '';
}
- // The date picker expects the date to be in the local timezone.
- // But .toISOString() converts it to UTC with zero offset.
- // So we need to subtract the timezone offset.
- dateCopy.setMinutes(dateCopy.getMinutes() - dateCopy.getTimezoneOffset());
if (inputType === 'date') {
return dateCopy.toISOString().substring(0, 10);
}
if (inputType === 'datetime-local') {
+ // The date picker expects the date to be in the local timezone.
+ // But .toISOString() converts it to UTC with zero offset.
+ // So we need to subtract the timezone offset.
+ dateCopy.setMinutes(dateCopy.getMinutes() - dateCopy.getTimezoneOffset());
return dateCopy.toISOString().substring(0, 19);
}
return dateCopy.toISOString().substring(0, 10);
@@ -73,6 +73,9 @@ function GridFilterInputDate(props: GridFilterInputDateProps) {
setIsApplying(true);
filterTimeout.start(rootProps.filterDebounceMs, () => {
const date = new Date(value);
+ if (type === 'date') {
+ date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
+ }
applyValue({ ...item, value: Number.isNaN(date.getTime()) ? undefined : date });
setIsApplying(false);
}); I will mark this as a good first issue since this is fairly easy to fix. |
Here is a quick recording of the filtering with the fix I just posted: Screen.Recording.2024-04-18.at.10.08.16.mov |
@michelengelen In your video at 0:07 mark: |
Hey @elawad |
Thanks @cherniavskii Looks good on initial testing! I'll run through some tests to ensure date/time works as intended. |
@elawad Thanks! 🤝 |
@elawad: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey. |
Steps to reproduce
Demo: https://mui.com/x/react-data-grid/column-definition/#column-types
Steps:
EST -4
, or any negative offset.dateCreated
.Current behavior
Filter by Date changes to previous day.
Expected behavior
Date stays as what was selected in Filter.
Context
No response
Your environment
npx @mui/envinfo
Search keywords: data grid filter date time zone
Order ID: 79011
The text was updated successfully, but these errors were encountered: