Yet Another Pretty Date JavaScript
I can’t let this Pretty Date thing go. I decided to use a modification of John Resig’s Pretty Date JavaScript implementation written by Dean Landolt and shared in the comments on John’s page. The script was an obvious choice for the next iteration of Alarmd, which is nearing completion as I type.
The more I used Dean Landolt’s script, the more problems I began to see with his implementation. It was a good start, but definitely had bugs. His assumptions translating from integer second differences to human readable labels stretched too far at times (there is an error in logic to say anything between 24 hours and 48 hours from now can be labeled “Tomorrow”), and he was a bit loose with his difference categories (assumed average month length was 28 days, and always used Math.floor instead of rounding — 47 hours from now would be labeled “1 Day”). It was great code otherwise, and I definitely liked the way he used the while loop to run through the comparisons.
So, I’ve cleaned up his great start, and am releasing it to the world in the spirit of cooperation and open sauce. You just read that typo out loud didn’t you?
Download: Yet Another Pretty Date Implementation (2 KB)
Update: Dates for this script must have a specific ISO8601 format: YYYY-MM-DDTHH:MM:SSZ (in UTC) where T and Z are literals.
Update: This script has been moved to Github.
25 Replies
Dean Landolt Disqus
25 Mar 2008 at 01:39PMZach Leatherman Disqus
25 Mar 2008 at 09:17PMJauder Ho Disqus
27 Mar 2008 at 06:33AMZach Leatherman Disqus
28 Mar 2008 at 04:15AMGary Sherman Disqus
05 May 2008 at 08:39PMHunka Disqus
20 May 2008 at 12:30PMunwiredbrain Disqus
28 Jun 2008 at 02:28PMunwiredbrain Disqus
29 Jun 2008 at 02:21AMZach Leatherman Disqus
08 Jan 2009 at 12:57AMunwiredbrain Disqus
08 Jan 2009 at 07:10AMwebmack Disqus
21 Jan 2009 at 01:37AMwebmack Disqus
21 Jan 2009 at 01:45AMDonny Kurnia Disqus
18 Apr 2009 at 12:15PMDonny Kurnia Disqus
18 Apr 2009 at 12:20PMtristan Disqus
11 Jun 2009 at 11:54PMZach Leatherman Disqus
12 Jun 2009 at 01:03AMtristan Disqus
12 Jun 2009 at 01:06AMZach Leatherman Disqus
13 Jun 2009 at 01:38PMSherman Monroe Disqus
05 Aug 2011 at 03:00PMZach Leatherman Disqus
05 Aug 2011 at 05:35PMJohnie R Disqus
19 Oct 2011 at 01:07AMAravind NC Disqus
07 Feb 2012 at 09:43AM