Humane dates with unobtrusive javascript…
I stumbled upon a little piece of code from John Resig (of jQuery fame) that fuzzies up dates on the fly. This script hits on some of my favorite patterns: humanity in interface design, unobtrusive javascript, and microformats, with both human and machine-readable dates.
But I’m none too fond of the the design — the default-operator cascade thing seems a bit obfuscated. An alternative was proposed in the comments, so I picked up on that and extended it a bit. I hacked it up to handle timezones properly and deal with future dates. Oh, and bloated it with a few extra lines to handle more than a few weeks worth of a date ranges.
Now it will break out the length of time from now at every level: minutes, hours, days, weeks, months, years and even centuries, just for good measure. It will return yesterday or tomorrow; last week or next week; last year; just now; yada yada yada.
Have a look at humane.js for more.
February 10th, 2008 at 5:00 am
February 23rd, 2008 at 2:51 pm
I just found the original at John’s site, and decided to try it out. I have a slightly different date format (”2008-01-28T20:24:17-08:00″ vs. “2008-01-28T20:24:17Z”), so I ran into a little trouble, but then I saw your comments about having worked out the UTC issue. I still have the same problem with yours, for which I have written a small work around, but I like the changes and enhancements that you have made … I think I’m going to go with your version.
Thanks!
February 23rd, 2008 at 11:39 pm
ISO 8601 Date Formatting, Client-side…
I went searching through the Internet looking for a script to convert my new ISO 8061 dates back into something a little nicer to look at, and I found almost exactly what I was looking for on John Resig’s site: JavaScript Pretty Date. The only li…
March 2nd, 2008 at 1:02 pm
You have a comma at the end of line 63, after the last element in the array you’re creating. This works, but as I understand it isn’t recommended.
Great script, btw, and thanks for carrying the jQuery plugin part through to your version.
–dhc–
March 25th, 2008 at 8:53 am