Easier expression of time periods
|Reported by:||nbachiyski||Owned by:||nacin|
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.