[wp-trac] [WordPress Trac] #9272: Expand human_time_diff()'s abilities

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 9 10:21:30 UTC 2012


#9272: Expand human_time_diff()'s abilities
-------------------------------------------------+-------------------------
 Reporter:  Viper007Bond                         |       Owner:
     Type:  enhancement                          |  Viper007Bond
 Priority:  normal                               |      Status:  new
Component:  Date/Time                            |   Milestone:  Future
 Severity:  normal                               |  Release
 Keywords:  has-patch needs-testing rtl-         |     Version:  2.8
  feedback                                       |  Resolution:
-------------------------------------------------+-------------------------

Comment (by westi):

 Replying to [comment:26 Viper007Bond]:
 > Alright, quite a few changes. :)
 >
 > * Now accepts arguments as an array. Props dd32.
 >
 > * Added "context" parameter that controls how the unit names are
 translated. Are more contexts needed? For example past versus future? Dumb
 English speaker here. :)
 >
 > * The separator can be controlled via the arguments, as can the unit
 labels.
 >
 > * Removed the units filter. This function won't work with units smaller
 than a second and I don't forsee people wanting to output "X decades". ;)
 >
 > * Add two helper functions per dd32's idea for the difference usage
 contexts. '''TODO:''' Go through existing usages of `human_time_diff()` in
 core and replace them with the context helper functions.

 I like the extension of the functionality of the function here but not the
 way in which is is achieved.

 I think we should aim to have the api look something like this:

  * {{{human_time_diff( $from, $to = '' )}}} - current "duration" based
 behaviour - e.g. 5 days, 4 hours
  * {{{human_time_diff_ago( $from, $to = '' )}}} - returns 5 days, 4 hours
 ago
  * {{{human_time_diff_old( $from, $to = '' )}}} - returns 5 days, 4 hours
 old
  * {{{__human_time_diff_helper( $args )}}} - private helper function which
 takes the $from, $to, $varients as arguments and is used to implement all
 three other functions.

 This gives us a simpler external API, a simpler handler function because
 it gets the labels to use passed in and they can live in the calling
 functions, an easy to extend function if you want to use it in another
 context.

 We also need a more correct way to handle RTL than array_reversing and
 crossing our fingers :)

 Rather than taking an array of labels we should probably have an array of
 variants e.g:

  * %d days, %d seconds ago
  * %d hours, %d seconds ago

 This gives translators full control.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9272#comment:34>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list