-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: add timezone support on date fields #10896
Conversation
packages/payload/src/fields/baseFields/timezone/timezoneOptions.ts
Outdated
Show resolved
Hide resolved
@jacobsfletch did you pull the branch down and test this when you reviewed? If not I plan to do this later today before we merge. |
I think we may want to use |
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.
Few last changes to make here:
- The
supportedTimezones
array exported from Payload should be renameddefaultTimezones
- This should be typed with a new
Timezone[]
type - The
supportedTimezones
property should accept a function that threadsdefaultTimezones
as an argument - Need to type
supportedTimezones
to ensure values are strictly an IANA timezone
packages/payload/src/fields/baseFields/timezone/supportedTimezones.ts
Outdated
Show resolved
Hide resolved
Added a few more tests to ensure UTC values are set as expected between the summer and winter times (daylight savings). Also tests for the below Timezone selector is now clearable. If date field is required and timezone is not provided but enabled it will now throw an error as well. |
🚀 This is included in version v3.23.0 |
Adds support for timezone selection on date fields.
Summary
New
admin.timezones
config:New
timezone
property on date fields:Configuration
All date fields now accept
timezone: true
to enable this feature, which will inject a new field into the configuration using the date field's name to construct the name for the timezone column. SopublishingDate
will havepublishingDate_tz
as an accompanying column. This new field is inserted during config sanitisation.Dates continue to be stored in UTC, this will help maintain dates without needing a migration and it makes it easier for data to be manipulated as needed. Mongodb also has a restriction around storing dates only as UTC.
All timezones are stored by their IANA names so it's compatible with browser APIs. There is a newly generated type for
SupportedTimezones
which is reused across fields.We handle timezone calculations via a new package
@date-fns/tz
which we will be using in the future for handling timezone aware scheduled publishing/unpublishing and more.UI
Dark mode
![image](https://private-user-images.githubusercontent.com/35137243/408280534-fcebdb7f-be01-4382-a1ce-3369f72b4309.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NzA5MTQsIm5iZiI6MTczOTQ3MDYxNCwicGF0aCI6Ii8zNTEzNzI0My80MDgyODA1MzQtZmNlYmRiN2YtYmUwMS00MzgyLWExY2UtMzM2OWY3MmI0MzA5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDE4MTY1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE3OTlmMDAzM2U0MTEwZjIyNjAxZmFjZWI4NTY1MTFmOTI3ZWM2N2MzN2Q1Y2FiY2IyNjdmYzk2ZDljZTM1ZjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.P-X6lBwvVstUrvYxTY67GmNHDY-MkDu36y9Aw67yNj8)
Light mode
![image](https://private-user-images.githubusercontent.com/35137243/408280558-dee2f1c6-4d0c-49e9-b6c8-a51a83a5e864.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NzA5MTQsIm5iZiI6MTczOTQ3MDYxNCwicGF0aCI6Ii8zNTEzNzI0My80MDgyODA1NTgtZGVlMmYxYzYtNGQwYy00OWU5LWI2YzgtYTUxYTgzYTVlODY0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0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