Repository navigation
Post summary: Show "Immediately" and relative publish dates in the Date row #86367
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e8cf30
Core fields: Add a `publish_date` field reading "Immediately"
oandregal e6a6eb3
View config: Summarize the post form `date` panel with `publish_date`
oandregal 928cdfa
Core fields: Word the `publish_date` field as the post summary did
oandregal 20b3c9b
E2E: Expect the post summary wording of the `date` panel
oandregal b862b2a
Core fields: Leave the `publish_date` summary empty in an untouched b…
oandregal 7cbd4d9
Backport changelog: Add the core backport of the `date` panel summary
oandregal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| https://github.com/WordPress/wordpress-develop/pull/15517 | ||
|
|
||
| * https://github.com/WordPress/gutenberg/pull/86367 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/core-fields/src/post_type_supports/publish_date/field.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <?php | ||
| /** | ||
| * The publish date of a post, as a form summarizes it, for every post type | ||
| * but the design ones. It reads the date of the post, so its JavaScript parts | ||
| * (`getValue` and `render`) are in `field.tsx`, next to this file. | ||
| * | ||
| * It is only meant as the summary of the `date` field in a form panel, so | ||
| * lists can't show, sort, or filter by it: they keep the `date` field, whose | ||
| * value is never "Immediately". | ||
| * | ||
| * @package WordPress | ||
| */ | ||
|
|
||
| return array( | ||
| 'type' => 'datetime', | ||
| 'label' => __( 'Publish date' ), | ||
| 'readOnly' => true, | ||
| 'enableHiding' => false, | ||
| 'enableSorting' => false, | ||
| 'filterBy' => false, | ||
| ); |
12 changes: 12 additions & 0 deletions
12
packages/core-fields/src/post_type_supports/publish_date/field.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { FieldsScriptParts } from '../../types'; | ||
| import type { PostWithDate } from '../date/types'; | ||
| import PublishDateView from './view'; | ||
|
|
||
| /** | ||
| * The JavaScript parts of the publish date field; its data is in | ||
| * `field.php`. | ||
| */ | ||
| export const fieldExtensions: FieldsScriptParts< PostWithDate >[ string ] = { | ||
| getValue: ( { item } ) => item.date, | ||
| render: PublishDateView, | ||
| }; |
124 changes: 124 additions & 0 deletions
124
packages/core-fields/src/post_type_supports/publish_date/get-publish-date-label.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { __, _x, isRTL, sprintf } from '@wordpress/i18n'; | ||
| import { dateI18n, getDate, getSettings } from '@wordpress/date'; | ||
|
|
||
| /* | ||
| * The publish date wording of the post summary, as the editor's | ||
| * `getPostScheduleLabel()` and `getFullPostScheduleLabel()` have it. This | ||
| * script module can't import the editor, so the strings keep their source and | ||
| * context to share its translations. | ||
| */ | ||
|
|
||
| /** | ||
| * The full publish date with the site's timezone, e.g. "November 5, 2026 | ||
| * 9:24 am UTC+0". | ||
| * | ||
| * @param dateAttribute The post date. | ||
| * @return The full label. | ||
| */ | ||
| export function getFullPublishDateLabel( dateAttribute: string | null ) { | ||
| const date = getDate( dateAttribute ); | ||
|
|
||
| const timezoneAbbreviation = getTimezoneAbbreviation(); | ||
| const formattedDate = dateI18n( | ||
| // translators: Use a non-breaking space between 'g:i' and 'a' if appropriate. | ||
| _x( 'F j, Y g:i\xa0a', 'post schedule full date format' ), | ||
| date | ||
| ); | ||
| return isRTL() | ||
| ? `${ timezoneAbbreviation } ${ formattedDate }` | ||
| : `${ formattedDate } ${ timezoneAbbreviation }`; | ||
| } | ||
|
|
||
| /** | ||
| * The publish date in words, the first that applies: | ||
| * | ||
| * 1. "Immediately", for a reset or floating date; | ||
| * 2. the full date with the site's timezone, when the user's timezone differs | ||
| * from the site's, as "today" or "tomorrow" would be ambiguous; | ||
| * 3. "Today at 9:24 am"; | ||
| * 4. "Tomorrow at 9:24 am"; | ||
| * 5. "November 12 9:24 am", within the current year; | ||
| * 6. "November 12, 2027 9:24 am", otherwise. | ||
| * | ||
| * @param dateAttribute The post date. | ||
| * @param options Options. | ||
| * @param options.isFloating Whether the date floats, see isDateFloating(). | ||
| * @param options.now The current date, for tests. | ||
| * @return The label. | ||
| */ | ||
| export function getPublishDateLabel( | ||
| dateAttribute: string | null | undefined, | ||
| { isFloating = false, now = new Date() } = {} | ||
| ) { | ||
| if ( ! dateAttribute || isFloating ) { | ||
| return __( 'Immediately' ); | ||
| } | ||
|
|
||
| if ( ! isTimezoneSameAsSiteTimezone( now ) ) { | ||
| return getFullPublishDateLabel( dateAttribute ); | ||
| } | ||
|
|
||
| const date = getDate( dateAttribute ); | ||
|
|
||
| if ( isSameDay( date, now ) ) { | ||
| return sprintf( | ||
| // translators: %s: Time of day the post is scheduled for. | ||
| __( 'Today at %s' ), | ||
| // translators: If using a space between 'g:i' and 'a', use a non-breaking space. | ||
| dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date ) | ||
| ); | ||
| } | ||
|
|
||
| const tomorrow = new Date( now ); | ||
| tomorrow.setDate( tomorrow.getDate() + 1 ); | ||
|
|
||
| if ( isSameDay( date, tomorrow ) ) { | ||
| return sprintf( | ||
| // translators: %s: Time of day the post is scheduled for. | ||
| __( 'Tomorrow at %s' ), | ||
| // translators: If using a space between 'g:i' and 'a', use a non-breaking space. | ||
| dateI18n( _x( 'g:i\xa0a', 'post schedule time format' ), date ) | ||
| ); | ||
| } | ||
|
|
||
| if ( date.getFullYear() === now.getFullYear() ) { | ||
| return dateI18n( | ||
| // translators: If using a space between 'g:i' and 'a', use a non-breaking space. | ||
| _x( 'F j g:i\xa0a', 'post schedule date format without year' ), | ||
| date | ||
| ); | ||
| } | ||
|
|
||
| return dateI18n( | ||
| // translators: Use a non-breaking space between 'g:i' and 'a' if appropriate. | ||
| _x( 'F j, Y g:i\xa0a', 'post schedule full date format' ), | ||
| date | ||
| ); | ||
| } | ||
|
|
||
| function getTimezoneAbbreviation() { | ||
| const { timezone } = getSettings(); | ||
|
|
||
| if ( timezone.abbr && isNaN( Number( timezone.abbr ) ) ) { | ||
| return timezone.abbr; | ||
| } | ||
|
|
||
| const symbol = Number( timezone.offset ) < 0 ? '' : '+'; | ||
| return `UTC${ symbol }${ timezone.offsetFormatted }`; | ||
| } | ||
|
|
||
| function isTimezoneSameAsSiteTimezone( date: Date ) { | ||
| const { timezone } = getSettings(); | ||
|
|
||
| const siteOffset = Number( timezone.offset ); | ||
| const dateOffset = -1 * ( date.getTimezoneOffset() / 60 ); | ||
| return siteOffset === dateOffset; | ||
| } | ||
|
|
||
| function isSameDay( left: Date, right: Date ) { | ||
| return ( | ||
| left.getDate() === right.getDate() && | ||
| left.getMonth() === right.getMonth() && | ||
| left.getFullYear() === right.getFullYear() | ||
| ); | ||
| } | ||
53 changes: 53 additions & 0 deletions
53
packages/core-fields/src/post_type_supports/publish_date/view.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import type { PostWithDate } from '../date/types'; | ||
| import { isDateFloating } from '../date/is-date-floating'; | ||
| import { getPublishDateLabel } from './get-publish-date-label'; | ||
|
|
||
| interface PostWithDateAndId extends PostWithDate { | ||
| id?: number; | ||
| type?: string; | ||
| } | ||
|
|
||
| /* | ||
| * The publish date of a post in words, as the post summary has it: see | ||
| * getPublishDateLabel(). | ||
| */ | ||
| export default function PublishDateView( { | ||
| item, | ||
| }: { | ||
| item: PostWithDateAndId; | ||
| } ) { | ||
| // The saved status, not the edited one: a status picked in the same form | ||
| // doesn't change whether the date floats until the post is saved. | ||
| const savedStatus = useSelect( | ||
| ( select ) => { | ||
| if ( ! item.type || ! item.id ) { | ||
| return undefined; | ||
| } | ||
| const saved: { status?: string } | undefined = select( | ||
| coreStore | ||
| ).getEntityRecord( 'postType', item.type, item.id ); | ||
| return saved?.status; | ||
| }, | ||
| [ item.type, item.id ] | ||
| ); | ||
|
|
||
| // A bulk edit passes only the edits made so far, so a date it hasn't | ||
| // touched is absent: each post keeps its own, and none reads | ||
| // "Immediately". A reset date is `null`, not absent. | ||
| if ( item.date === undefined ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| { getPublishDateLabel( item.date, { | ||
| isFloating: isDateFloating( { | ||
| ...item, | ||
| status: savedStatus ?? item.status, | ||
| } ), | ||
| } ) } | ||
| </> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This file matches
packages/editor/src/components/post-schedule/label.js(how labels are computed in the old inspector) line by line.