Lasso Soft Inc. > Home

[date_relative]

Linkdate_relative
AuthorJason Huck
CategoryDate
Version8.5.x
LicensePublic Domain
Posted07 Jun 2007
Updated07 Jun 2007
More by this author...

Description

This tag converts the given date into relative terms, such as "Yesterday", "Today", "Tomorrow", or "Next Thursday." Appends the time in 12-hour format. Requires [lp_date_leapyear].

Sample Usage

var('date') = date->subtract( -week=2)&;

loop(30);
	date_relative($date) + '
\n'; $date->add( -day=1); /loop;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'relative',
	-namespace='date_',
	-req='in', -type='date', -copy,
	-opt='format', -type='string',
	-priority='replace',
	-description='Outputs the given date in relative format (yesterday/today/tomorrow).'
);
	!local_defined('format') ? local('format' = '%D %h:%M %p');

	local(
		'rel' = string,
		'out' = string,
		'day' = @#in->dayofyear,
		'daysinyear' = (lp_date_leapyear ? 366 | 365),
		'today' = @date->dayofyear
	);
	
	local(
		'yesterday' = (#today - 1 == 0 ? #daysinyear | #today - 1),
		'tomorrow' = (#today + 1 > #daysinyear ? 1 | #today + 1)
	);

	select(true);
		case(#today == #day);
			#rel = 'Today';			
		case(#yesterday == #day);
			#rel = 'Yesterday';				
		case(#tomorrow == #day);
			#rel = 'Tomorrow';
		case(#day > #tomorrow && #day < #today + 7);
			#rel = 'This ' + #in->format('%A');
		case(#day >= #today + 7 && #day < #today + 14);
			#rel = 'Next ' + #in->format('%A');
		case;
			return(#in->format(#format)->lowercase&);
	/select;
	
	#out = (#rel + ' ' + #in->format('%h:%M %p')->lowercase&);
	return(#out);
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft