WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#27271 closed enhancement (fixed)

Add a filter to human_time_diff()

Reported by: slimndap Owned by:
Milestone: 4.0 Priority: normal
Severity: normal Version: 3.8.1
Component: Formatting Keywords: has-patch commit
Focuses: template Cc:

Description

The human_time_diff function lacks a filter.
It would be useful to add extra formatting options.

Currently, if the difference is 2 hours and 40 minutes the result of human_time_diff is '2 hours'.

With a filter you could change it to be more specific: 2 hours, 40 mins.

The filter could look like this:

return apply_filters( 'human_time_diff', $since, $diff );

Attachments (4)

27271.diff (623 bytes) - added by MikeHansenMe 4 years ago.
Add filter and brackets
add-filter-to-human_time_diff#27271.diff (2.6 KB) - added by slimndap 4 years ago.
Added $from and $to to apply_filters. Added documentation for the hook.
add-filter-to-human_time_diff#27271.2.diff (1.0 KB) - added by slimndap 4 years ago.
Added $from and $to to apply_filters. Added documentation for the hook. This time without unrelated change from another commit.
add-filter-to-human_time_diff#27271.3.diff (1.0 KB) - added by slimndap 4 years ago.
New attempt at creating a working patch.

Download all attachments as: .zip

Change History (16)

@MikeHansenMe
4 years ago

Add filter and brackets

#1 @MikeHansenMe
4 years ago

  • Keywords has-patch added

#2 follow-up: @DrewAPicture
4 years ago

  • Keywords needs-docs added

Any new hook will need accompanying hook docs.

#3 follow-up: @SergeyBiryukov
4 years ago

$from and $to should probably be passed to the filter as well.

@slimndap
4 years ago

Added $from and $to to apply_filters. Added documentation for the hook.

#4 in reply to: ↑ 2 @slimndap
4 years ago

Replying to DrewAPicture:

Any new hook will need accompanying hook docs.

I uploaded a patch with documentation for the new hook.

#5 in reply to: ↑ 3 ; follow-up: @slimndap
4 years ago

Replying to SergeyBiryukov:

$from and $to should probably be passed to the filter as well.

I added $from and $to to the new filter.

#6 @SergeyBiryukov
4 years ago

  • Keywords 4.0-early added
  • Milestone changed from Awaiting Review to Future Release

#7 in reply to: ↑ 5 @DrewAPicture
4 years ago

  • Keywords needs-docs removed

Replying to slimndap:

Replying to SergeyBiryukov:

$from and $to should probably be passed to the filter as well.

I added $from and $to to the new filter.

At a glance, the hook docs look good. Thanks.

Protip: Make sure to pass --no-prefix when you generate the diff so you don't get all of the extra information attached to it like in your latest patch.

#8 follow-up: @SergeyBiryukov
4 years ago

  • Keywords needs-refresh added

The patch also includes unrelated change from [27558].

@slimndap
4 years ago

Added $from and $to to apply_filters. Added documentation for the hook. This time without unrelated change from another commit.

#9 in reply to: ↑ 8 @slimndap
4 years ago

Replying to SergeyBiryukov:

The patch also includes unrelated change from [27558].

I removed the unrelated change and uploaded a new patch.

#10 @SergeyBiryukov
4 years ago

The latest patch is "backwards" (it's suggesting to remove what isn't there and add what is).

git diff --no-prefix should handle this in the proper order.

@slimndap
4 years ago

New attempt at creating a working patch.

#11 @danielbachhuber
3 years ago

  • Keywords commit added; 4.0-early needs-refresh removed
  • Milestone changed from Future Release to 4.0

#12 @SergeyBiryukov
3 years ago

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

Fixed in [28670].

Note: See TracTickets for help on using tickets.