Make WordPress Core

Opened 9 days ago

Closed 9 days ago

Last modified 7 days ago

#61535 closed defect (bug) (fixed)

human_time_diff(): Do not use abbreviations in minutes

Reported by: wildworks's profile wildworks Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Formatting Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by wildworks)

I discovered this problem while researching an issue with Gutenberg: https://github.com/WordPress/gutenberg/issues/62976

As I understand it, when relative times are displayed in the block editor, this format is referenced. No abbreviations are used for minutes:

https://github.com/WordPress/wordpress-develop/blob/d3ac93a93839fbe5e441309607786bacdad755cd/src/wp-includes/script-loader.php#L444-L447

On the other hand, in PHP, i.e. the human_time_diff() function, abbreviations (min/mins) are only used for minutes:

https://github.com/WordPress/wordpress-develop/blob/d3ac93a93839fbe5e441309607786bacdad755cd/src/wp-includes/formatting.php#L3887-L3888

As a result, relative times can be formatted differently depending on whether they're expressed in JS or PHP.

One example is the Post Date block. If the post date is within an hour of the current time and relative format is enabled, it will be displayed as 1 minute/10 minutes in the block editor and represented as 1 min / 10 mins on the frontend.

I suggest not using abbreviations in human_time_diff() functions.

Attachments (2)

post-date-block-block-editor.png (24.9 KB) - added by wildworks 9 days ago.
Post Date Block: Editor
post-date-block-frontend.png (8.7 KB) - added by wildworks 9 days ago.
Post Date Block: Frontend

Download all attachments as: .zip

Change History (10)

@wildworks
9 days ago

Post Date Block: Editor

@wildworks
9 days ago

Post Date Block: Frontend

#1 @wildworks
9 days ago

  • Description modified (diff)

This ticket was mentioned in PR #6942 on WordPress/wordpress-develop by @wildworks.


9 days ago
#2

  • Keywords has-patch has-unit-tests added

#3 @SergeyBiryukov
9 days ago

  • Milestone changed from Awaiting Review to 6.7

#4 @SergeyBiryukov
9 days ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58600:

Date/Time: Replace abbreviations for minutes in human_time_diff().

This ensures that relative times are formatted the same way in both JS and PHP.

Follow-up to [1976], [2124], [4658], [41018], [56496].

Props wildworks.
Fixes #61535.

@SergeyBiryukov commented on PR #6942:


9 days ago
#5

Thanks for the PR! Merged in r58600.

#6 follow-up: @wildworks
9 days ago

Hi @SergeyBiryukov,

Thank you for the commit.

Looking at r58600, it seems that the singular form is now minutes.

Also, I missed it, but maybe we should remove the abbreviation ((min=minute)) from the comment here as well:

https://github.com/WordPress/wordpress-develop/blob/57910f67dd4ba8b1db1a5699be916ce0c805a69b/src/wp-includes/formatting.php#L3887

#7 in reply to: ↑ 6 @SergeyBiryukov
7 days ago

Replying to wildworks:

Looking at r58600, it seems that the singular form is now minutes.

Indeed, that was a typo on my part :)

Also, I missed it, but maybe we should remove the abbreviation ((min=minute)) from the comment here as well

Good catch, thanks!

#8 @SergeyBiryukov
7 days ago

In 58601:

Date/Time: Correct singular form for minutes in human_time_diff().

Follow-up to [58600].

Props wildworks.
See #61535.

Note: See TracTickets for help on using tickets.