Lasso Soft Inc. > Home

[vz_elapsedtime]

Linkvz_elapsedtime
AuthorPier Kuipers
CategoryDate
Version8.5.x
LicensePublic Domain
Posted25 Jul 2008
Updated25 Jul 2008
More by this author...

Description

Given a date and optional time, this tag will return a string displaying its offset compared to the current time in the format "[n] [units] ago".

Sample Usage

[vz_elapsedtime(field('creation_date'))]
-> '23 minutes ago'
-> '5 days ago'
-> '1 month ago'

If the tag would return "1 day ago", it changes the output to
-> 'yesterday'

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.

if(!lasso_tagexists('vz_elapsedtime'));
	define_tag('elapsedtime',
		-description='given a date and optional time, this tag will return a string displaying its offset compared to the current time in the format "[n] [units] ago".',
		-namespace='vz_',
		-required='datetime',
		-Priority='Replace');
		local('timenow'=date);
		local('output'=string);
		local('timespans'=(array('year', 'month', 'week', 'day', 'hour', 'minute', 'second')));
		iterate(#timespans, local('tmp'));
			local('diff'=(date_difference(#timenow, #datetime, #tmp)));
			if(#diff > 0);
				if((#tmp=='day')&&(#diff==1));
					#output = 'yesterday';
				else;
					#output = #diff+' '#tmp+(#diff>1?'s')+' ago';
				/if;
				loop_abort;
			/if;
		/iterate;
		return(@#output);
	/define_tag;
/if;

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