PDA

View Full Version : Suggestion: "Smart" Date Format



Eric24
21 May 2008, 12:53 PM
An idea...If it's out there, maybe I'm not looking in the right way...

A date format that would be very useful is one that returns "Yesterday", "Today", and "Tomorrow" (and even "Overmorgen", a special word in Danish and other Nordic languages that means "the day after tomorrow"), a date without the year for any dates in the current year, and an otherwise "full" date otherwise; it should also be accompanied by an option to include time in a specified format. This is similar to the posting timestamps that appear in the forums and is used in several email clients. The point to it is that "Yesterday" is more instantly intuitive than a date, and the time something occurred is less relevant the longer ago it was (at least in a list of events).

Of course, text for each of these "near" possibilities and formatting strings for "this year" and "other year" dates would be configs to allow for localization. It's almost an encapsulation of three date/time formatting strings, the one selected being based on the passed date's relationship to "now" (which could be optionally passed if the app didn't want to use "true now").

Examples of possible output:
1) Date=Now @ 10:10: Today 10:10
2) Date=Yesterday @ 8:15: Yesterday 08:15
3) Date=Two Months Ago w/o time: March 22
4) Date=Last Year w/o time: August 15, 2007

evant
21 May 2008, 2:56 PM
Something like this?

http://www.datejs.com/

mystix
21 May 2008, 6:41 PM
Something like this?

http://www.datejs.com/

datejs authors have also provided Ext integration details:
http://groups.google.com/group/datejs/browse_thread/thread/b343b2eb7372405c

Eric24
22 May 2008, 7:13 AM
That is very cool (and useful), but it actually does the exact opposite of what I'm looking for. Its parsing abilities convert "Next Tuesday" to a date. What I'm looking for is the ability to convert a date to a "human scale" output. All the date formatters let you pick any mix of month/day/year/time, but none of them create "natural" dates. For example, to humans "Yesterday" or "Tomorrow" is a lot more descriptive and easier to digest than "05/21/2008" or even "May 21, 2008". Then in the next step (for a few days ago), maybe the time of the event matters, but for events that happened three weeks ago, it may not. What I envision is a date formatter that is passed the target date and an optional "comparison" date (which defaults to "now" if it's omitted), plus an array (?) of format strings and "ranges" (i.e., for dates longer ago than 3 weeks, use this format string; for dates longer ago than 1 year, use this one, etc.); by default, it would use yesterday, today, and tomorrow for dates that fall into that range, with an optional time format string to append. Again, this isn't on the top of my to-do list right now, so I may write it when it gets there, but I wanted to make sure nobody else had already done this.
--Eric

Lobos
22 May 2008, 7:39 AM
is it something like this you mean?

http://www.php.net/manual/en/function.strtotime.php

This is a php function that i have found extremely useful in the past.

mscdex
22 May 2008, 9:20 AM
What I'm looking for is the ability to convert a date to a "human scale" output.

You might want to take a look here (http://www.php.net/manual/en/function.date.php) and scroll down to a post made by "Bandit".

Eric24
22 May 2008, 9:31 AM
No, this does the conversion in the same direction as datejs (i.e., "natural" dates to a date/time object).

Eric24
22 May 2008, 9:33 AM
Hmmm. Bandit's post is going in the right direction, but it's a slightly different tack on the idea.