Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion components/post-date/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ interface PostDateProps {
*/
format?: string;

/**
* The timezone to use for formatting.
* When not provided, dateI18n falls back to the WordPress site timezone.
*/
timezone?: string;

/**
* Remaining props to pass to the time element.
*/
Expand All @@ -47,14 +53,14 @@ interface PostDateProps {
export const PostDate: React.FC<PostDateProps> = ({
placeholder = __('No date set', 'tenup'),
format,
timezone,
...rest
}) => {
const { postId, postType, isEditable } = usePost();

const [date, setDate] = useEntityProp('postType', postType, 'date', postId as string);
const [siteFormat] = useEntityProp('root', 'site', 'date_format');
const settings: DateSettings = getSettings();
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;

const resolvedFormat = format || siteFormat || settings.formats.date;

Expand Down
1 change: 1 addition & 0 deletions components/post-date/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ function BlockEdit() {
| ---------- | ----------------- | -------- | -------------------------------------------------------------- |
| `placeholder` | `string` | `No date set` | |
| `format` | `string` | | Uses the WordPress date format setting of the site |
| `timezone` | `string` | | Uses the WordPress site timezone when not provided |
| `...rest` | `object` | `{}` | |
Loading