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

feat: add timezone support on date fields #10896

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

paulpopus
Copy link
Contributor

@paulpopus paulpopus commented Jan 30, 2025

Adds support for timezone selection on date fields.

Summary

  • New timezone config option on date fields
  • New timezone.supportedTimezones in global admin config to allow customisation of available timezones
    • timezone.defaultTimezone sets the default selection
  • formatOptions has been moved to its own file
  • supportedTimezones is an array of possible timezones with IANA values exported from payload
  • siblingField is now threaded through to each field for direct sibling config access
  • generates a new type for SupportedTimezones which is then reused across 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. So publishingDate will have publishingDate_timezone as an accompanying column. This new field is inserted during config sanitisation.

Example:

{
  type: 'date',
  name: 'date',
  timezone: true,
}

In the future we can turn this to accept a config object as well if needed.

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.

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

Light mode
image

Left to do:

  • Add translation for the Timezone: label
  • Add exports for new utilities from payload and ui packages
  • Add e2e tests for deeply nested fields inside tabs, arrays and blocks
  • Add test for custom timezone options
  • Add docs

jacobsfletch
jacobsfletch previously approved these changes Feb 4, 2025
@paulpopus paulpopus disabled auto-merge February 4, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants