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

Post Date: Allow user to pick Site Default, a suggested date format, or a custom date format #39209

Merged
merged 20 commits into from
Mar 18, 2022

Conversation

noisysocks
Copy link
Member

@noisysocks noisysocks commented Mar 4, 2022

Description

Closes #38751.

Kapture.2022-03-11.at.12.39.06.mp4

Changes the Post Date block so that you can choose between using the site's default date format, a suggested format, or a completely custom format.

How I arrived at the suggested date formats

Which formats should we suggest? is a difficult question as different locales have different date formatting conventions.

In my opinion there are a few requirements:

  1. Users should see suggestions that are appropriate for their locale.
  2. We shouldn't overwhelm users with too many options.
  3. Theme developers should be able to do basically whatever they want.

We can meet requirement 3 by allowing the theme developer to type any arbitrary date format into a text field.

If we pick a small set of suggested formats, as in #38751 (comment), then we will meet requirement 2 but struggle to meet requirement 1. This is because any list we come up with is bound to not be appropriate in some locales. For example, 4/20/22 is typical in US English but 20/04/2022 is typical elsewhere. Or, "April 20, 2022" makes sense in US English but this would be "20 April 2022" in UK English and "20. April 2022" in German.

We could flood the dropdown with hundreds of different options so as to cover all locales and meet requirement 1, but then this would be an overwhelming amount of options and therefore not meet requirement 2.

So what I've opted to do is to start from four categories: short, medium, long, and full. This is inspired by what Apple has in System Preferences. For the short, medium, and long categories, I added the option of showing the time as well. This gives seven options. Each option is localised depending on the site's language. That is, the suggested formats will change depending on what language WordPress is set to.

Option US English en_US UK English en_GB German de
Short 4/20/2022 20/04/2022 20.04.2022
Medium Apr 20, 2022 20 Apr 2022 20. Apr 2022
Long April 20, 2022 20 April 2022 20. April 2022
Full Wednesday, April 20, 2022 Wednesday, 20 April 2022 Mittwoch, 20. April 2022
Short + time 4/20/2022 4:20 AM 20/04/2022 4:20 am 20.04.2022 04:20
Medium + time Apr 20, 2022 4:20 AM 20 Apr 2022 4:20 am 20. Apr 2022 04:20
Long + time April 20, 2022 4:20 AM 20 April 2022 4:20 am 20. April 2022 04:20
ISO 2022-04-20 2022-04-20 2022-04-20

Notes

  • A null attributes.format is what denotes that the user has selected Site default. This is the default.
  • Existing Post Date blocks will remain as they are, even if they use the site's default format. I don't think we can properly migrate this as we don't know whether attributes.format === siteFormat because the user intended that or if it's just a coincidence.
  • We don't need to access the @wordpress/date settings as we can get everything we need from /wp/v2/settings (the site entity).
  • I need to update the Comment Date block with the same changes. (Maybe the dropdown should be a block editor component? (Or a block supports? 😬))
  • I removed a bunch of unnecessary string/array manipulation from the is12Hour calculation and fixed the logic of this. Previously it was only looking for a but technically a 12 hour format string could just be e.g. g:i with no a.

Testing Instructions

  1. Open the site editor.
  2. Find a Post Date block and go into its block settings.
  3. Experiment with different Format settings.
  4. If Site default is selected, check that changing the date setting in Options → General changes how the Post Date appears in the frontend.
  5. If Custom is selected, check that you can enter a custom date format string.

Checklist:

@noisysocks noisysocks added [Type] Enhancement A suggestion for improvement. Internationalization (i18n) Issues or PRs related to internationalization efforts Needs Design Feedback Needs general design feedback. [Block] Post Date Affects the Post Date Block labels Mar 4, 2022
@noisysocks noisysocks requested a review from ramonjd March 4, 2022 05:04
@github-actions
Copy link

github-actions bot commented Mar 4, 2022

Size Change: +1.12 kB (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-editor/index.min.js 146 kB +679 B (0%)
build/block-editor/style-rtl.css 15.1 kB +118 B (+1%)
build/block-editor/style.css 15.1 kB +114 B (+1%)
build/block-library/blocks/gallery/editor-rtl.css 961 B -4 B (0%)
build/block-library/blocks/gallery/editor.css 964 B -3 B (0%)
build/block-library/blocks/gallery/style-rtl.css 1.51 kB -101 B (-6%)
build/block-library/blocks/gallery/style.css 1.51 kB -103 B (-6%)
build/block-library/editor-rtl.css 9.96 kB -4 B (0%)
build/block-library/editor.css 9.96 kB -5 B (0%)
build/block-library/index.min.js 169 kB +244 B (0%)
build/block-library/style-rtl.css 11.2 kB -122 B (-1%)
build/block-library/style.css 11.3 kB -122 B (-1%)
build/blocks/index.min.js 46.8 kB +289 B (+1%)
build/components/index.min.js 218 kB +64 B (0%)
build/core-data/index.min.js 14.3 kB +77 B (+1%)
ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/admin-manifest/index.min.js 1.24 kB
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.49 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.56 kB
build/block-library/blocks/cover/style.css 1.56 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 708 B
build/block-library/blocks/navigation-link/editor.css 706 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.89 kB
build/block-library/blocks/navigation/style.css 1.88 kB
build/block-library/blocks/navigation/view.min.js 2.85 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 521 B
build/block-library/blocks/post-comments/style.css 521 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 389 B
build/block-library/blocks/pullquote/style.css 388 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 201 B
build/block-library/blocks/quote/style.css 201 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 99 B
build/block-library/blocks/separator/editor.css 99 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 172 B
build/block-library/blocks/separator/theme.css 172 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 744 B
build/block-library/blocks/site-logo/editor.css 744 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 235 B
build/block-library/blocks/template-part/editor.css 235 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 934 B
build/block-library/common.css 932 B
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/theme-rtl.css 665 B
build/block-library/theme.css 670 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/components/style-rtl.css 15.6 kB
build/components/style.css 15.6 kB
build/compose/index.min.js 11.2 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.19 kB
build/date/index.min.js 31.9 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.53 kB
build/edit-navigation/index.min.js 16.1 kB
build/edit-navigation/style-rtl.css 4.04 kB
build/edit-navigation/style.css 4.05 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 29.8 kB
build/edit-post/style-rtl.css 7.07 kB
build/edit-post/style.css 7.07 kB
build/edit-site/index.min.js 43.8 kB
build/edit-site/style-rtl.css 7.44 kB
build/edit-site/style.css 7.42 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.39 kB
build/edit-widgets/style.css 4.39 kB
build/editor/index.min.js 38.4 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 4.29 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 957 B
build/nux/index.min.js 2.12 kB
build/nux/style-rtl.css 751 B
build/nux/style.css 749 B
build/plugins/index.min.js 1.98 kB
build/preferences/index.min.js 1.2 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 611 B
build/react-i18n/index.min.js 704 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

Comment on lines 60 to 69
...[
_x( 'M jS', 'date format option' ),
_x( 'M j, Y', 'date format option' ),
_x( 'M j, Y, h:i A', 'date format option' ),
_x( 'F j, Y', 'date format option' ),
_x( 'd/m/Y', 'date format option' ),
].map( ( suggestedFormat ) => ( {
key: suggestedFormat,
name: dateI18n( suggestedFormat, date ),
} ) ),
Copy link
Contributor

@talldan talldan Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably an issue in trunk too, so it might be something to fix separately, but thought I'd mention it as it might be a fix we can roll in to this PR.

The labels could be improved for screenreaders. Both 'Feb 25, 2022' and 'Februrary 25, 2022' are announced as 'February 25th 2022' using Voiceover. I it does some normalisation of dates. I'm not sure if we can add some screenreader text into the CustomSelectControl items that also contains the format.

Let me know if you want me to create a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. That's tricky. I'm not entirely sure what the expectations would be for folks using screen readers. Go ahead and create a new issue so that we can ask for feedback on that from a11y folks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a new issue - #39278

Testing again, and there's also no way to tell which item in the dropdown is currently checked. 😞

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a quick look at the SelectControl component, and it looks like it doesn't currently set the selected attribute on option elements (here). I was wondering if that could be the culprit? (Probably something to look at separately to this PR?)

@noisysocks noisysocks changed the title Post Date: Allow user to pick Site Default, or a suggested date format Post Date: Allow user to pick Site Default, a suggested date format, or a custom date format Mar 7, 2022
@noisysocks noisysocks marked this pull request as ready for review March 7, 2022 05:59
@noisysocks
Copy link
Member Author

I thought some more about what formats to suggest to the user (see How I arrived at the suggested date formats in the description) and made some changes there. I also added the ability to set a custom format (see updated video in the description) which I think is necessary as we can't cover every date format that a theme author might want in the dropdown.

Keen for feedback! Particularly on my thinking around what date formats to show. Internationalisation makes it very tricky.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great to me @noisysocks, thanks for the excellent PR description and explanation of the decisions involved! I particularly like being able to edit the custom date format in realtime in the editor UI. While this is an advanced control, I agree, it'd be really great to be able to open up this level of control to themers, and keeping it hidden behind the Custom setting means that we're not unintentionally exposing it to novice users 👍

image

In a future follow-up, it'd be fun for us to explore a WYSIWYG interface for dragging/dropping formatting for dates, but that exploration is for another time 😃

One thing I noticed, since you mentioned i18n, is that as an Australian user of my US English test site, it isn't immediately noticeable from the formatting suggestions if a number is day or month. I'm not sure if there's anything we can really do easily for it at this stage, but just thought I'd mention it:

image

packages/block-library/src/post-date/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/post-date/edit.js Outdated Show resolved Hide resolved
@noisysocks
Copy link
Member Author

In a future follow-up, it'd be fun for us to explore a WYSIWYG interface for dragging/dropping formatting for dates, but that exploration is for another time

Yeah, this is probably the only way to not have to make any compromises. It's obviously a bit of work to implement such an interface, though. I'm not sure if the cost vs benefit stacks up just yet.

One thing I noticed, since you mentioned i18n, is that as an Australian user of my US English test site, it isn't immediately noticeable from the formatting suggestions if a number is day or month. I'm not sure if there's anything we can really do easily for it at this stage, but just thought I'd mention it:

We could change the date in the dropdown to use a sample date with a day greater than 12. For example, 20221-01-25. I'm not sure if this is more unclear, though. It might lead users to get confused and think that their post's publish date is the sample date. What do you think?

@noisysocks
Copy link
Member Author

We could change the date in the dropdown to use a sample date with a day greater than 12. For example, 20221-01-25. I'm not sure if this is more unclear, though. It might lead users to get confused and think that their post's publish date is the sample date. What do you think?

Another reason to do this is that if we're using the post date it's not always clear what the difference is between the medium date which abbreviates the month name and the long date which doesn't. For example, if the post date is in May, it won't be clear because May is already three letters.

I'll switch to using a sample date. We can change our minds later.

@andrewserong
Copy link
Contributor

It's obviously a bit of work to implement such an interface, though. I'm not sure if the cost vs benefit stacks up just yet.

Agreed, for the moment we probably need a stronger use case for date formats being frequently edited to make it a worthwhile investment of time in building it.

I'll switch to using a sample date. We can change our minds later.

I think the sample date approach sounds like a good way forward to me!

@noisysocks
Copy link
Member Author

I moved the dropdown into its own component and am using that in the Comment Date block now too. Easiest way to test that is to edit a post, edit the template (Post inspector → Template → Edit), and then insert a Comments Query Loop block.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is testing really well for me @noisysocks, thanks for re-arranging things and adding in the extra test! Just found a tiny formatting issue in the documentation where I've added a comment.

✅ Works with site's datetime formatting settings
✅ Post Date and Comment Date blocks work correctly with the new component
✅ Suggested and custom date formats work as expected, and escaped characters can be used to inject a word like "at":

image

✅ Custom date formats are matched against the list of suggested formats, so on editor reload if there's a match, the suggested format is highlighted if there's a match, and if not, the custom field is pre-selected

Thanks again for the detailed testing notes / explanations, the code change LGTM! It'll be good to get some design feedback on the suggested formats, too — they look like a good starting point to me, though I was wondering what the preference would be between capitalised / not capitalised AM/PM / am/pm?

@noisysocks
Copy link
Member Author

Thanks for the review! I definitely want to get some design feedback on my thinking in the description and the list of suggested formats before merging.

though I was wondering what the preference would be between capitalised / not capitalised AM/PM / am/pm?

From my research this seems to be locale specific. Or at least that's how Apple has implemented it. American English uses "AM", UK English uses "am", and most other languages use 24 hour time.

I appreciate that that's all pretty academic though. It's difficult to strike a balance between having suggestions that are correct for the site's locale and useful for theme developers while also not having hundreds of options in the dropdown. Again, feedback welcome 😅

@andrewserong
Copy link
Contributor

Again, feedback welcome

Thanks for the explanations, I didn't realise it varied so much by locale! That all sounds reasonable to me, and I quite like the defaults you've added. Let's see what the design experts think 😀

@kjellr
Copy link
Contributor

kjellr commented Mar 9, 2022

I think all the decisions here make sense. I like the presets, the idea to leverage localization, as well as the use of a sample date to ensure that the previews are clear.

I like the Custom functionality too, but I'm wondering if we have that UI pattern (selecting custom in a dropdown to show an additional field) in place for other blocks anymore? I think the closest we have at the moment is the custom field for font size, which uses a slightly different paradigm:

type

That doesn't feel quite right here though, since I think it would over-emphasize the custom option. I'd like one more designer to take a look and weigh in. @jasmussen or @jameskoster perhaps?

@jasmussen
Copy link
Contributor

jasmussen commented Mar 9, 2022

Took it for a spin, here are the test instructions in GIF form:
date

Very nice, works well. A few thoughts; to echo Kjell, the "Custom" one feels a bit weird since it's the only dropdown option that shows a separate input field when selected. Reusing the same format as is used for font size would be a nice bit of consistency.

The bigger problem with "Custom", I feel, is its juxtaposition against the Site default option at the top; to an extent, these date formats are ALL custom, because they are detached from the site-wide setting. I wonder if we should do something similar as to what's done with the Layout option, and have an a toggle to inherit the default date format:
inherit

If we do that, we should show that default layout format in help text below the toggle, when it's enabled. I also wonder if we can find a different term than "Custom", possibly just be more verbose? "Custom date format"?

We have a tendency to proliferate collapsible panels and use them like subheadings. For such a single purpose block, I don't think we need to. Instead of a panel for "Format settings" with a single option, and a panel for "Link settings" with a single toggle, could we just have a single "Settings" panel, that included both date format and link settings? "Link to post" feels plenty descriptive on its own.

Finally, this is a long list of options:
Screenshot 2022-03-09 at 15 13 55

Blink, and you'll miss that the 3 of them include the clock timestamp. Should we reduce to, say, 5 options? Or if we do need this many options, we might want to look at a custom dropdown so we could add separators and/or subheadings.

@jameskoster
Copy link
Contributor

these are ALL and detached from the default.

I was going to say exactly this. If it's not bad practise to only have two options in a segmented control, perhaps that would be an option versus the toggle?

Screenshot 2022-03-09 at 14 19 27

@noisysocks noisysocks removed the Needs Design Feedback Needs general design feedback. label Mar 9, 2022
@noisysocks
Copy link
Member Author

Great suggestions ❤️ thank you!


let postDate = date ? (
<time dateTime={ dateI18n( 'c', date ) } ref={ timeRef }>
{ dateI18n( resolvedFormat, date ) }
{ dateI18n( format || siteFormat, date ) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need a hook somewhere to ensure siteFormat is available.

For me at least, there seems to be a race condition whereby, if I refresh the Post Editor with a Post Date block and the site default selected, both format and siteFormat are undefined.

This is only in the Post Editor. The Site Editor works as expected.

The result is, when refreshing the page, format() complains that it cannot find a length.

Adding a new Post Date block reveals that the value is indeed returned at some point after refresh.

Copy link
Member Author

@noisysocks noisysocks Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah bugger. I guess it happens while the site entity is loading.

I added a fallback to the @wordpress/date format in b3fcfda.

Let me know if that fixes it for you.

@noisysocks noisysocks force-pushed the try/better-post-date-format-settings branch from ce9835d to c9d954d Compare March 17, 2022 04:39
@noisysocks
Copy link
Member Author

Alrighty I swapped the toggle group for a regular toggle component, like in #39209 (comment). I think it definitely is clearer now that "custom" means only one thing. I'll update the video in the description.

@jameskoster: In the design you had two labels for the toggle but unfortunately that's not how our toggle component works. Toggles only have one label which is on the right. I could add text above the toggle but it wouldn't work like a regular label (clicking it should focus the field) and it'd probably confuse assistive technology users.

I worked around this by using "Default format (March 27, 2022)" for the copy.

Screen Shot 2022-03-17 at 15 42 54

We could also put the date on a new line which I think might look a little nicer.

Screen Shot 2022-03-17 at 15 45 38

Happy to hear other suggestions.

@noisysocks noisysocks added [Type] Feature New feature to highlight in changelogs. and removed [Type] Enhancement A suggestion for improvement. labels Mar 17, 2022
@jasmussen
Copy link
Contributor

Happy to hear other suggestions.

The toggle should be able to have helptext on an entirely new line, like Drop Cap right?
Screenshot 2022-03-17 at 09 58 31

☝️ note there's something off about the spacing there, but that's a separate issue.

@noisysocks
Copy link
Member Author

Yes correct!

I think it feels a little disconnected though:

Screen Shot 2022-03-18 at 11 20 02

I don't think there's a problem with the spacing, it's just that the help text usually shows a sentence or two of copy:

Screen Shot 2022-03-18 at 11 21 15

I pushed 08d3e41 which moves the date to a new line under the label, which is my preference:

Screen Shot 2022-03-18 at 11 41 49

I'd love to get this merged and do any further iteration in follow-up PRs! What we have here is a lot better than what's in trunk 😀

@noisysocks
Copy link
Member Author

Separately, now that we've combined all the settings I think I spotted a bug. While editing something like the single post template in the site editor the link toggle label seems to be broken:

Screenshot 2022-03-11 at 10 35 57

I presume this is because it's looking for a post type or title that is not provided.

Good catch. Fixed in d6cc73e.

Copy link
Contributor

@talldan talldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works really well, great job iterating here.

This is a good improvement over what's in trunk, so I really think it's worth merging and then following up with any further design changes.

As an aside, I noticed another bug with the formats while testing, but it seems like an existing issue with the dateI18n utility rather than anything introduced here, so I've made an issue for it - #39567.

@talldan talldan merged commit 5921283 into trunk Mar 18, 2022
@talldan talldan deleted the try/better-post-date-format-settings branch March 18, 2022 07:12
@github-actions github-actions bot added this to the Gutenberg 12.9 milestone Mar 18, 2022
@jasmussen
Copy link
Contributor

Nice one, thanks for working on this.

Let's remember to follow up on the help text, so this isn't the only place where it's used like this:
Screenshot 2022-03-18 at 09 30 49

For lack of larger improvements such as those Jay suggested, we could start with something simple, like this:

Screenshot 2022-03-18 at 09 35 24

CC: @ciampo, I think there's some margin between toggle and help text we need to tweak so it's smaller. More specifically, when a toggle has helptext, the toggle itself doesn't need to have bottom margin, it appears, since the helptext itself has that.

@ciampo
Copy link
Contributor

ciampo commented Mar 18, 2022

CC: @ciampo, I think there's some margin between toggle and help text we need to tweak so it's smaller. More specifically, when a toggle has helptext, the toggle itself doesn't need to have bottom margin, it appears, since the helptext itself has that.

Good catch! @mirka , can this also be part of the recent style "normalisation" treatment that you're applying across components?

@mirka
Copy link
Member

mirka commented Mar 18, 2022

can this also be part of the recent style "normalisation" treatment that you're applying across components?

Yes, that will fit in perfectly with the work in #38730@jasmussen I'll ping you on the PR for a check when we do ToggleControl.

jostnes pushed a commit to jostnes/gutenberg that referenced this pull request Mar 23, 2022
…or a custom date format (WordPress#39209)

* Post Date: Allow user to pick Site Default, or a suggested date format

* Update suggested formats to be more localizable

* Add support for custom formats

* Move is12Hour check to function

* Distinguish between 'long' and 'full' like Apple does

* Use a sample date in the dropdown so as to better illustrate the formats

* Split out DateFormatControl and update the Comment Date block

* Add basic tests for is12HourFormat

* Fix markdown link formatting

* Combine 'Format settings' and 'Link settings' into single 'Settings' panel

* WIP

* Use Default / Custom radio control

Re-jig DateFormatControl into DateFormatPicker. Users now select either
Default or Custom in a ratio control and, then, if they select Custom,
they can select a suggested date format or enter a manual one.

* Simplify suggested date formats

* Use date and time formats from @wordpress/date as a fallback

* Use 'Enter your own date format'

* Explain what null means in the doc comment

* Use ToggleControl for selecting a default date

* Use __experimental like a coward

* Move example of default format to new line

* Fix 'Link to post' label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Date Affects the Post Date Block Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Feature New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Post Date Block: Offer better defaults
9 participants