-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pickers] Add proper support for UTC and timezones (#8261)
- Loading branch information
1 parent
be1732e
commit 13658f0
Showing
201 changed files
with
2,823 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function BasicTimezoneProp() { | ||
const [value, setValue] = React.useState(dayjs.utc('2022-04-17T15:30')); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="America/New_York" | ||
label={'Rendered in "America/New_York"'} | ||
/> | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="Europe/Paris" | ||
label={'Rendered in "Europe/Paris"'} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as React from 'react'; | ||
import dayjs, { Dayjs } from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function BasicTimezoneProp() { | ||
const [value, setValue] = React.useState<Dayjs | null>( | ||
dayjs.utc('2022-04-17T15:30'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="America/New_York" | ||
label={'Rendered in "America/New_York"'} | ||
/> | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="Europe/Paris" | ||
label={'Rendered in "Europe/Paris"'} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/data/date-pickers/timezone/BasicTimezoneProp.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="America/New_York" | ||
label={'Rendered in "America/New_York"'} | ||
/> | ||
<TimePicker | ||
value={value} | ||
onChange={setValue} | ||
timezone="Europe/Paris" | ||
label={'Rendered in "Europe/Paris"'} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function BasicValueProp() { | ||
const [value, setValue] = React.useState( | ||
dayjs.tz('2022-04-17T15:30', 'America/New_York'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<TimePicker | ||
label={'Value timezone: "America/New_York"'} | ||
value={value} | ||
onChange={setValue} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import dayjs, { Dayjs } from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { TimePicker } from '@mui/x-date-pickers/TimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function BasicValueProp() { | ||
const [value, setValue] = React.useState<Dayjs | null>( | ||
dayjs.tz('2022-04-17T15:30', 'America/New_York'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<TimePicker | ||
label={'Value timezone: "America/New_York"'} | ||
value={value} | ||
onChange={setValue} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<TimePicker | ||
label={'Value timezone: "America/New_York"'} | ||
value={value} | ||
onChange={setValue} | ||
/> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function DayjsTimezone() { | ||
const [value, setValue] = React.useState( | ||
dayjs.tz('2022-04-17T15:30', 'America/New_York'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as React from 'react'; | ||
import dayjs, { Dayjs } from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import timezone from 'dayjs/plugin/timezone'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
|
||
dayjs.extend(utc); | ||
dayjs.extend(timezone); | ||
|
||
export default function DayjsTimezone() { | ||
const [value, setValue] = React.useState<Dayjs | null>( | ||
dayjs.tz('2022-04-17T15:30', 'America/New_York'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react'; | ||
import dayjs from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
|
||
dayjs.extend(utc); | ||
|
||
export default function DayjsUTC() { | ||
const [value, setValue] = React.useState(dayjs.utc('2022-04-17T15:30')); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react'; | ||
import dayjs, { Dayjs } from 'dayjs'; | ||
import utc from 'dayjs/plugin/utc'; | ||
import Stack from '@mui/material/Stack'; | ||
import Typography from '@mui/material/Typography'; | ||
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'; | ||
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'; | ||
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker'; | ||
|
||
dayjs.extend(utc); | ||
|
||
export default function DayjsUTC() { | ||
const [value, setValue] = React.useState<Dayjs | null>( | ||
dayjs.utc('2022-04-17T15:30'), | ||
); | ||
|
||
return ( | ||
<LocalizationProvider dateAdapter={AdapterDayjs}> | ||
<Stack spacing={2}> | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> | ||
</Stack> | ||
</LocalizationProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<DateTimePicker value={value} onChange={setValue} /> | ||
<Typography> | ||
Stored value: {value == null ? 'null' : value.format()} | ||
</Typography> |
Oops, something went wrong.