Monday, November 08, 2010 at 12:02 AM.

system.verbs.builtins.date.viewDate

on viewDate (when, flShortDayOfWeek=false) {
	<<Changes
		<<9/12/10; 9:28:43 AM by DW
			<<Add new optional parameter, flShortDayOfWeek. If true, only return the first three characters of the day of the week: Mon, Tue, Wed, Thu, Fri, Sat, Sun.
		<<9/11/10; 11:46:53 PM by DW
			<<Return a version of the date suitable for displaying. If it's within the last week, return the day of the week. If it's today, return the time. Otherwise return a short version of the date.
	local (now = clock.now ());
	when = date (when);
	if date.sameday (when, now) {
		return (date.timestring (when, false))}
	else {
		local (oneweek = 60 * 60 * 24 * 7);
		local (cutoff = now - oneweek);
		if when > cutoff { //within the last week
			local (s = date.dayOfWeekToString (date.dayOfWeek (when)));
			if flShortDayOfWeek {
				s = string.mid (s, 1, 3)};
			return (s)}
		else {
			return (date.shortstring (when))}}};
bundle { //test code
	local (when = clock.now (), i);
	for i = 1 to 6 {
		when = date.yesterday (when)};
	when = date ("9/10/2010; 5:34:32 AM");
	dialog.alert (viewDate (when))}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.