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

[data grid] dateTime column how to show date/time for another timezone #11804

Closed
oleksandrfomin5995 opened this issue Jan 24, 2024 · 3 comments
Closed
Labels
component: data grid This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it support: commercial Support request from paid users

Comments

@oleksandrfomin5995
Copy link

oleksandrfomin5995 commented Jan 24, 2024

The problem in depth

I need to display the date and time returned from the server in a certain timezone (in the datagrid column with 'dateTime' type).
The date I receive is in UTC (e.g 2024-01-24T11:52:12). Let's say I want to convert this date to America/Bogota timezone (UTC -5), so that the datagrid displays 24/01/2024 06:52AM

I'm converting the date to the desired timezone like this

      valueGetter: (params: GridValueGetterParams) => {
        const timeZone = params.api.getRow(params.id).siteView?.timeZone;

        return dayjs(params.value).tz(timeZone).toDate();
      }

The only problem I encounter is that converting the dayjs string to JS Date object automatically adds the client's UTC offset. So far I have not managed to find a way around it.

Your environment

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: datagrid datetime
Order ID: 67193

@oleksandrfomin5995 oleksandrfomin5995 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jan 24, 2024
@michelengelen
Copy link
Member

michelengelen commented Jan 24, 2024

Hey @oleksandrfomin5995 there is a problem with dayjs and using any timezone with a 00:00/00:00 offset (not only UTC). This PR should fix it, but the maintainer does not seem very active lately. Since this is out of our control we cannot do anything but advice you to use a different date package (e.g. moment) to handle such use-cases.
Sry 🙇🏼

@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 24, 2024
@michelengelen michelengelen changed the title DataGrid dateTime column how to show date/time for another timezone [data grid] dateTime column how to show date/time for another timezone Jan 24, 2024
@oleksandrfomin5995
Copy link
Author

Hey @oleksandrfomin5995 there is a problem with dayjs and using any timezone with a 00:00/00:00 offset (not only UTC). This PR should fix it, but the maintainer does not seem very active lately. Since this is out of our control we cannot do anything but advice you to use a different date package (e.g. moment) to handle such use-cases. Sry 🙇🏼

Is there an example of valueGetter method using moment?

@michelengelen
Copy link
Member

Here is a basic example: Moment in datagrid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! external dependency Blocked by external dependency, we can’t do anything about it support: commercial Support request from paid users
Projects
None yet
Development

No branches or pull requests

2 participants