-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 Block: Offer better defaults #38751
Comments
@kjellr @beafialho curious what you'd suggest here. |
I actually ended up using some non-standard dates in Twenty Twenty-Two by manually editing the block markup. 😄 Here are a number of our most frequently used date configs:
I haven't added an exact timestamp to any theme recently, but I know that's helpful for some high-volume sites. So perhaps we could include something like this:
As noted elsewhere, an |
I've been looking into the moving (and static) parts of dates and trying to find the best place to start tackling this specific issue while keeping longer term possibilities open. I've made a bunch of assumptions here, so will be very happy to be corrected on anything. 😄 For now they're notes. I'll come back and refine them and add some steps we could take to move forward. Where the current default date formats come fromThe date package provides the default formats and other date settings for our app. time: 'g: i a',
date: 'F j, Y',
datetime: 'F j, Y g: i a',
datetimeAbbreviated: 'M j, Y g: i a', WordPress Core "overwrites" these default settings in script-loader.php. Here we call the date package's method It's also the reason why, when we select a date format in WordPress General Settings, the date format is available an an option in the Post Date block. This means that, no matter how much we extend the default settings in Gutenberg, the WordPress Core inline script will overwrite them. In the Post Date Block and potentially elsewhere, we grab the date settings via __experimentalGetSettings() and use the formats in our select box. Adding new date formats to Post DateFirstly, it's important to note that the property names in the date package have corresponding type definitions, so we cannot add new formats without causing compile errors. Any new ones we add would need their own type definitions. Unless there's a good reason to expect specific property names, I think we should refactor the date package's types to remove the explicit property names. As an initial step to achieve the minimum for this PR, we'd add the new formats in the Post Date block, and completely bypass the date package. This would work, but would mean that we'd have a bespoke set of date formats out there so I'd say it's not sustainable. Ideally we'd add our new formats to the WordPress Core overrides, and also add them to the date package. It seems more robust to have the formats available across the editor, especially if we want to use the formats across the Gutenberg app. The best example (there are without doubt others) I could find is the Latest Comments Block, which outputs the dates using This option is the value selected in General Settings. And can, and I'd say usually is, different from the Post Date format. Longer term possibilities/ideasIn the future, we might like to allow theme authors to extend the date format list with additional formats. Some ideas to achieve this:
Some more related, but possibilty even longer term tasks:
|
@ramonjd Did you do this as an initial step? Should we keep this moving forward with some of your suggestions above? |
Thanks for the ping. No I haven't yet returned to this one yet (I want to!), but I think it would be good to look at extending the WordPress core overrides. |
I find it confusing that the first two options in the dropdown come from the site's Date Format and Time Format settings but that there's no indication of that. It's also weird that, because we store the format (e.g. I think the Post Date block should offer the user the choice of using the site's Date Format setting or one of a handful of formats that we suggest based on the user's locale. So in other words the dropdown would look like something like this: If Site default is selected then updating Date Format in Settings → General would update what's shown on the frontend. If Custom is selected then a text field appears which lets the user type in a date format. |
Thanks for looking at this @noisysocks
I like the idea of integrating the currently-selected site date format into the list
I hacked together something for this custom date demo and seem to recall it didn't take long at all:
Good spotting. That's also something I'd have expected to happen. It'd be awesome be able to offer the ability to standardize the dates. Do you think we should extend the same functionality for all blocks that display a date? The Latest Comments Block pulls |
Yeah definitely.
Probably we can leave Latest Comments how it is, since that block is on its way out in favour of Comments Query Loop. I'd say we should mirror whatever we do for the Post Date block to the Comment Date block, though. |
I started implementing what I described above in #39209. Let me know if you think it's a good idea and I'll polish it up! |
Yep, this is wrong. If the block doesn't serialize a specific format descriptor we should fallback to what the site has defined globally wherever we display dates. That should be clear in the control we offer in the UI as well. |
I'd echo @ramonjd's wishlist item here, it'd be nice with a toggle to convert whatever format chosen to be relative for at least 7 days ("Just now", "10m ago", "3h ago", "2 days ago", etc.) |
Relative date can be nice, but let's keep it as a separate thing from this issue :) |
Was a separate ticket ever created for the relative date feature? +1 for that as a native option. |
@cdils I can't find an issue. Would you have time to create one? 🙏🏻 |
@ramonjd Done. :) |
Thanks for the follow up :) |
What problem does this address?
The post date block currently has restricted defaults, and editing this means opening the code editor.
What is your proposed solution?
Add in some more default options in the dropdown. Going further allow extending this by the theme and/or pulling in the defaults from WordPress itself.
Hat tip @mtias
The text was updated successfully, but these errors were encountered: