|
3 | 3 | */ |
4 | 4 | import { registerBlockBindingsSource } from '@wordpress/blocks'; |
5 | 5 | import { store as coreDataStore } from '@wordpress/core-data'; |
6 | | -import { dateI18n } from '@wordpress/date'; |
| 6 | +import { format } from '@wordpress/date'; |
7 | 7 |
|
8 | 8 | /** |
9 | 9 | * Get the value of a specific field from the SCF fields. |
@@ -88,7 +88,18 @@ const processFieldBinding = ( |
88 | 88 | if ( ! fieldValue ) { |
89 | 89 | return ''; |
90 | 90 | } |
91 | | - return dateI18n( fieldConfig?.display_format, fieldValue ) || ''; |
| 91 | + /** |
| 92 | + * On the server side, we use `date_i18n()` (PHP) to format dates, see |
| 93 | + * https://developer.wordpress.org/reference/functions/date_i18n/. |
| 94 | + * However, the client-side (JS) version, `dateI18n()`, seems to have a bug |
| 95 | + * that gets the timezone wrong. When the WordPress install's timezone is set |
| 96 | + * to UTC, and the client timezone is UTC+x, it will return the _previous_ day. |
| 97 | + * This is probably because a date without a time is treated as midnight UTC, |
| 98 | + * which is still the previous day in UTC+x timezones (i.e. east of Greenwich). |
| 99 | + * Since we aren't interested in times and timezones for date picker fields, |
| 100 | + * we can simply use the `format()` function to format the date. |
| 101 | + */ |
| 102 | + return format( fieldConfig?.display_format, fieldValue ) || ''; |
92 | 103 | case 'image': |
93 | 104 | // fieldValue is a (numeric) image ID. |
94 | 105 | const imageObj = getMedia( fieldValue ); |
|
0 commit comments