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.

Download Date in a Nice Tone v1.2.1

WordPress Plugin Directory page for Date in a Nice Tone