[date_relative]

Description

Link: [date_relative]
Author: Jason Huck
Category: Date
Version: 8.5.x
License: Public Domain
Posted: Jun. 07, 2007
Updated: Jan. 01, 0001
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].

Parameters

-format string, optional Format to use for non-relative dates. Defaults to %D %h:%M %p.

Sample Usage

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

loop(30);
	date_relative($date) + '<br>\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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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

none

Email:


Password:



Newest

Most Popular