You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for UTC timezone in date fields (#14586)
Adds support for 'UTC' as a value for timezones. This was not previously
supported because we run a check on the values used against the runtime
of Intl API.
```ts
import { buildConfig } from 'payload'
const config = buildConfig({
// ...
admin: {
timezones: {
supportedTimezones: [
{
label: 'UTC',
value: 'UTC',
},
// ...other timezones
],
defaultTimezone: 'UTC',
},
},
})
```
Also fixes an issue when having only one timezone making it selected by
default.
Copy file name to clipboardExpand all lines: docs/admin/overview.mdx
+63-4Lines changed: 63 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -286,12 +286,14 @@ Users in the Admin Panel have the ability to choose between light mode and dark
286
286
287
287
The `admin.timezones` configuration allows you to configure timezone settings for the Admin Panel. You can customise the available list of timezones and in the future configure the default timezone for the Admin Panel and for all users.
288
288
289
+
Dates in Payload are always stored in UTC in the database. The timezone settings in the Admin Panel affect only how dates are displayed to editors to help ensure consistency for multi-region editorial teams.
|`supportedTimezones`| An array of label/value options for selectable timezones where the value is the IANA name eg. `America/Detroit`. Also supports a function that is given the defaultTimezones list.|
296
+
|`defaultTimezone`| The `value` of the default selected timezone. eg. `America/Los_Angeles`|
295
297
296
298
We validate the supported timezones array by checking the value against the list of IANA timezones supported via the Intl API, specifically `Intl.supportedValuesOf('timeZone')`.
297
299
@@ -330,6 +332,63 @@ const config = buildConfig({
330
332
})
331
333
```
332
334
335
+
### Extending supported timezones
336
+
337
+
For `supportedTimezones` we also support using a function that is given the defaultTimezones list. This allows you to easily extend the default list of timezones rather than replacing it completely.
338
+
339
+
```ts
340
+
import { buildConfig } from'payload'
341
+
342
+
const config =buildConfig({
343
+
// ...
344
+
admin: {
345
+
timezones: {
346
+
supportedTimezones: ({ defaultTimezones }) => [
347
+
...defaultTimezones, // list provided by Payload
348
+
{
349
+
label: 'Europe/Dublin',
350
+
value: 'Europe/Dublin',
351
+
},
352
+
{
353
+
label: 'Europe/Amsterdam',
354
+
value: 'Europe/Amsterdam',
355
+
},
356
+
{
357
+
label: 'Europe/Bucharest',
358
+
value: 'Europe/Bucharest',
359
+
},
360
+
],
361
+
defaultTimezone: 'Europe/Amsterdam',
362
+
},
363
+
},
364
+
})
365
+
```
366
+
367
+
### Using a UTC timezone
368
+
369
+
In some situations you may want the displayed date and time to match exactly what's being stored in the database where we always store values in UTC. You can do this by adding UTC as a valid timezone option.
370
+
Using a UTC timezone means that an editor inputing for example '1pm' will always see '1pm' and the stored value will be '13:00:00Z'.
371
+
372
+
```ts
373
+
import { buildConfig } from'payload'
374
+
375
+
const config =buildConfig({
376
+
// ...
377
+
admin: {
378
+
timezones: {
379
+
supportedTimezones: [
380
+
{
381
+
label: 'UTC',
382
+
value: 'UTC',
383
+
},
384
+
// ...other timezones
385
+
],
386
+
defaultTimezone: 'UTC',
387
+
},
388
+
},
389
+
})
390
+
```
391
+
333
392
## Toast
334
393
335
394
The `admin.toast` configuration allows you to customize the handling of toast messages within the Admin Panel, such as increasing the duration they are displayed and limiting the number of visible toasts at once.
0 commit comments