[wp-trac] [WordPress Trac] #20987: Easier expression of time periods

WordPress Trac wp-trac at lists.automattic.com
Sat Jun 16 07:22:53 UTC 2012


#20987: Easier expression of time periods
-------------------------+-----------------------------
 Reporter:  nbachiyski   |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:  has-patch
-------------------------+-----------------------------
 Numbers are cool. But sometimes they stand in the way of what we have to
 say.

 {{{
 set_transient( 'plugin_slugs', $plugin_slugs, 86400 );
 }}}

 From the context it's obvious that 86400 is a time period and with some
 calculation we can see it's 24 hours/1 day in seconds. Of course, it's not
 very readable, so usually in the code we see a clarifying comment:

 {{{
 // 1 day
 }}}

 This definitely helps. But we could do better. We can make the whole thing
 read naturally in English:
 {{{
 set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
 }}}

 This way we get all the information we need – we know the transient is set
 for one day, we can read this in plain English and we don't need to spare
 extra cycles to either make mathematical calculations or wait to the end
 of the line to see the actual period in the comment.

 In the patch is attached a new file {{{time-constants.php}}} which
 contains a couple of constants.

 All of them follow the pattern:
 <SINGULAR_OF_TIME_UNIT>_IN_<PLURAL_OF_TIME_UNIT>.

 For now there are only *_IN_SECONDS and *_IN_MINUTES, since that's what we
 found useful on WordPress.com.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20987>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list