Revised Wordpress Plugin “Date in a Nice Tone”
UPDATE: Crap, just found a bug. Will update later today. Fixed. (There’s some overlap between how “around a week” and the tail end of “a few days ago” is calculated, but I don’t think it makes a difference.)
On both this site and Brittany’s site, I’m using Mark Kirby’s excellent Date in a Nice Tone Wordpress plugin, which is what enables the date in the upper right corner of this post to be written out in loose English rather than just displaying a date.
Brittany wanted a modification that added “yesterday” to the available options—she felt that “freshly baked” for posts sitting in the 48 hours between right now and time posted was too long to be useful.
The plugin calculates its dates by using time (seconds) in a day and phrases everything in approximate language (i.e. “a couple of days ago”, “a few days ago”)—so the difference between “a couple of days ago” and “a few days ago” is if the post falls between 86400×2 seconds and 86400×3 seconds. (There are 86400 seconds in a day.)
This works fine when using approximate language, but “yesterday” is more precise because it needs to work off of midnight. (Unfortunately, this plugin doesn’t take into account timezones of the user; I’m pretty sure it just uses your web hosting server’s timezone.)
My equation for calculating “yesterday” is if the time between now and when posted is greater than the time elapsed today, and the time between now and when posted is less than the time elapsed today plus another full day, then it is yesterday.
I also changed how “if equal to or more than 2 days ago” is calculated so that it uses the same pattern as yesterday. Otherwise, you get a weird overlap where it’s not yesterday, but it’s less than 48 hours from the post, which would give you a less recent post showing “freshly baked” behind one showing “yesterday”.
I’m hardly a PHP programmer, so if you see any flaws in my code, please share a fix.
@Mark Kirby: If you like my revision, it’d be great if you added it to the version in the Wordpress Plugin Directory; if not, no worries, I’ll leave it here regardless. Thanks for writing (and sharing) your plugin.
Hey! You’re thinking like a programmer. I suits you.
It suits you. If I could, I would also suit you.
Well I have been eying a new Armani at Mario’s if you want to swing by there this weekend… ;)
Hi Jaacob,
Great stuff, thanks for contributing and writing about our plugin and we’re delighted its been of use to you.
For our blog we don’t post that often so we only wrote the plugin for the 48 hour period as freshly baked should rest for quite a while. Different people have different needs, and post at different paces so clearly for some, 48 hours will be too long.
In terms of the words, we wanted the the language of the time span to be quite wooly, and imprecise – so yesterday wouldn’t work on our blog, but recently added might.
What this points to is a probable need to expand the plugin to have an options screen allowing the user to select the terminology for different time periods, with a default set (perhaps as they are now).
When we can get something like that together, I think we’ll release a new version incorporating your new code to calculate the yesterday time span.
Cheers again,
The team at Ribot
Sounds great, looking forward to it.