Link | date_relative |
Author | Jason Huck |
Category | Date |
Version | 8.5.x |
License | Public Domain |
Posted | 07 Jun 2007 |
Updated | 07 Jun 2007 |
More by this author... |
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].
var('date') = date->subtract( -week=2)&; loop(30); date_relative($date) + '
\n'; $date->add( -day=1); /loop;
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;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft