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 Comments
Dean Landolt Disqus
25 Mar 2008Zach Leatherman Disqus
26 Mar 2008Jauder Ho Disqus
27 Mar 2008Zach Leatherman Disqus
28 Mar 2008Gary Sherman Disqus
06 May 2008Hunka Disqus
20 May 2008unwiredbrain Disqus
28 Jun 2008unwiredbrain Disqus
29 Jun 2008Zach Leatherman Disqus
08 Jan 2009unwiredbrain Disqus
08 Jan 2009webmack Disqus
21 Jan 2009webmack Disqus
21 Jan 2009Zach Leatherman Disqus
21 Jan 2009Frank Disqus
17 Mar 2009Zach Leatherman Disqus
17 Mar 2009Donny Kurnia Disqus
18 Apr 2009Donny Kurnia Disqus
18 Apr 2009tristan Disqus
12 Jun 2009Zach Leatherman Disqus
12 Jun 2009tristan Disqus
12 Jun 2009Zach Leatherman Disqus
13 Jun 2009Sherman Monroe Disqus
05 Aug 2011Zach Leatherman Disqus
05 Aug 2011Johnie R Disqus
19 Oct 2011Aravind NC Disqus
07 Feb 2012