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

Update the post schedule label to correctly reflect the date and time display settings #15757

Merged
merged 1 commit into from
Aug 26, 2019

Conversation

brentswisher
Copy link
Contributor

Description

Fixes #15654.

Updates the post schedule label to correctly reflect a user's date and time display preferences. This was previously using the "datetimeAbbreviated" format, which is not updated when a user changes their date/time settings.

Additionally, now if a user specifies a custom date or time format, it will be correctly reflected in the publish date.

An alternative to this approach would be to update the functionality that is setting the settings.formats.date and settings.formats.time to correctly set the time in settings.formats.datetime, and settings.formats.datetimeAbbreviated.

I opted for my approach over this because it will also pass through any totally custom date or time setting. Also, because I couldn't for the life of me find where settings.formats.time was getting updated when the site settings were updated.

If the other approach is preferred, I would be happy to revisit. Someone would just need to point me in the right direction for where those get set. It looks like it used to be in lib/client-assets.php but got removed here

How has this been tested?

For 24 hour time
Change time settings to use 24h time. (Settings > General > Time Format > H:i)
Create a post.
Schedule for any time past 12:00. (ie, 13:25).
Close popover by clicking outside.
Publish date now correctly lists 12:25

For custom date/time settings
Change date/time settings to use something custom:
(Settings > General > Time Format > G:i)
(Settings > General > Date Format > d-m-Y)
Create a post.
Schedule for any time before 12:00. (ie, 1:25).
Close popover by clicking outside.
Publish date now correctly display custom format of 21-05-2019 01:25

Screenshots

24 hour time
24 Hour Format

Custom date/time settings
Custom date and time

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@jorgefilipecosta jorgefilipecosta added [Feature] Document Settings Document settings experience [Type] Bug An existing feature does not function as intended labels May 21, 2019
@brentswisher brentswisher force-pushed the update/publish-date-time-setting branch from 613fa67 to 810b6c3 Compare June 26, 2019 12:01
@youknowriad youknowriad requested a review from a team July 4, 2019 11:14
@noisysocks noisysocks added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label Jul 4, 2019
@@ -9,7 +9,7 @@ export function PostScheduleLabel( { date, isFloating } ) {
const settings = __experimentalGetSettings();

return date && ! isFloating ?
dateI18n( settings.formats.datetimeAbbreviated, date ) :
dateI18n( `${ settings.formats.date } ${ settings.formats.time }`, date ) :
Copy link
Member

@jorgefilipecosta jorgefilipecosta Jul 5, 2019

Choose a reason for hiding this comment

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

Hi @brentswisher, thank you for your contribution 👍
Would it make sense to make this change in core:

https://github.com/WordPress/WordPress/blob/28a8f31ffa9dc238b56eb2413a728e861207b5af/wp-includes/script-loader.php#L615

Making datetimeAbbreviated format be the concatenation of time and date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potentially, I wasn't sure where it was defined in core - so thanks for pointing that out! That leads to another question - what is the purpose of the "datetimeAbbreviated" format? If I set my date and time format to custom things that are quite long, does it make sense to set something called dateTimeAbbreviated to that? Will updating that in core cause design issues in places where they are expecting a set formatting mask? There seemed to be a lot of questions I didn't know the answer to so I went with the smallest change to fix the issue, but if you think it warrants a larger discussion I am happy to pursue that as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jorgefilipecosta - My last comment had more questions and no answers so I tried to track this down a little better.

Investigating it looks like:

  • 'datetimeAbbreviated' as a format was added in this commit by @aldavigdis specifically for the use here in the post-schedule component
  • It is not used anywhere else in Gutenberg I can find
  • It is not used anywhere else in WordPress core I can find
  • The "I can find" part here is important, I am not confident enough in my understanding of WordPress as a whole to make the call is really isn't used anywhere and can be removed

I would propose we:

  1. Implement the change I have in this PR, so that 24hr time is supported and this issue can be closed.
  2. Open a separate issue here and in trac asking if the 'datetimeAbbreviated' format needs to remain, as it looks like it is not used. That way it will hopefully get some more experienced eyes on it that may know the history before removing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of bike shedding went on when I worked on this a year ago, but datetimeAbbreviated was added to satisfy some design requirements and review if I remember it correctly.

I'm not sure if decisions had been made on how to handle localisation of dates by then, but at the time, there were some issues with parsing dates from PHP in the React components.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @swissspidy, would it be possible to provide some feedback regarding the i18n of this string?

Copy link
Contributor

Choose a reason for hiding this comment

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

Both settings.formats.date and settings.formats.time are put through the translation function in the script loader. I've tested these changes with several different language settings and all looks to be working fine:
Screen Shot 2019-08-16 at 7 08 22 pm
I'm not sure what context datetime or datetimeAbbreviated could be useful in as they set a very specific formatting, as opposed to date and time which reflect the user settings. AFAICT neither of them are being used anywhere but, for the sake of fixing this annoying bug quickly, I vote we get this in and perhaps create a ticket to clean up all those formats later.

@brentswisher brentswisher self-assigned this Jul 11, 2019
@brentswisher brentswisher force-pushed the update/publish-date-time-setting branch from 810b6c3 to c42d8a6 Compare July 11, 2019 21:44
@brentswisher brentswisher added the Internationalization (i18n) Issues or PRs related to internationalization efforts label Aug 5, 2019
@mapk
Copy link
Contributor

mapk commented Aug 16, 2019

I just can't get this running on my local to test. Sorry.

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

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

These changes look good!

An alternative to this approach would be to update the functionality that is setting the settings.formats.date and settings.formats.time to correctly set the time in settings.formats.datetime, and settings.formats.datetimeAbbreviated.

I'm not sure that would make much difference, as it would just be a concatenation of the date and time settings that come from wp_admin. It's more a question of if we need a static datetime that is independent of what the user sets, or not. If it's not being used, probably best to scrap it altogether.

@mapk
Copy link
Contributor

mapk commented Aug 23, 2019

Just tested this and was able to get it running locally. It looks and works great from a design perspective. 👏

I switched around a few different settings and they worked.

@brentswisher
Copy link
Contributor Author

@jorgefilipecosta is this okay to merge or did you still have some reservations?

@tellthemachines tellthemachines merged commit 4d0d290 into master Aug 26, 2019
@tellthemachines tellthemachines deleted the update/publish-date-time-setting branch August 26, 2019 23:28
donmhico pushed a commit to donmhico/gutenberg that referenced this pull request Aug 27, 2019
@gziolo gziolo added this to the Gutenberg 6.5 milestone Aug 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Document Settings Document settings experience Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code Internationalization (i18n) Issues or PRs related to internationalization efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

24h time settings aren't respected in preview
7 participants