Using 'smart' dates, today

Written by Adrian Holovaty on December 20, 2002

Nathan Ashby-Kuhlman has posted some outstanding ideas on intelligent relative dates. Good stuff:

What if Web sites automatically made dates relative to the current date rather than the publication date? For example, suppose I refer to "Dec. 20, 2002" -- which right now for me is "tomorrow" -- using some JavaScript that will display whatever "Dec. 20" means to you, at the time you access this page.

He offers a JavaScript solution that displays dates in an intelligent, relative manner, according to the user's computer's system clock -- much like Peter Paul Koch's "document last modified" script (and somewhat similar, conceptually, to this site's smart anchoring). Wisely, Nathan points out several problems with this method -- namely the need for editors to tag dates in a special way and the reliance on the user's computer (a problem also apparent in chicagotribune.com's strike countdown a few months ago).

My take: How 'bout continuing to use relative dates ("today" or "tomorrow") in news stories but wrapping them in <abbr> tags that have a title attribute which contains the full date? That way, some of the technical problems Nathan pointed out can be avoided. It'd look something like this:

The code: <abbr title="December 20, 2002">today</abbr>

How it looks: today

This could be a more realistic short-term solution -- although I certainly believe manufacturers of content-management systems should incorporate the feature Nathan has proposed. (On the server side.)

(For more on abbreviations, see my recent entry on that topic. It was posted Tuesday.)

Comments

Posted by Simon Willison on December 20, 2002, at 1:58 p.m.:

Ian Hickson has a clever way of dealing with the local times problem using UTC, XBL and a piece of javascript which converts times from UTC to local time using the system clock - I'm sure it could be replicated in an IE friendly .hta script. See here for details. I'm quite fond of the "2 hours ago" approach taken by sites such as Google News and Textism but using javascript to convert it in to a more "solid" date is a very clever idea. The only disadvantage I can see (which is not an issue for Hixie's UTC based solution) is that pages must be dynamically generated for it to work.

Posted by Mark on December 20, 2002, at 9:11 p.m.:

For those who don't know (or are confused about why the above example doesn't work): abbr does nothing on IE/Win.

Comments have been turned off for this page.