Lasso Soft Inc. > Home

[time]

Linktime
AuthorJolle Carlestam
CategoryDate
Version8.x
LicensePublic Domain
Posted03 Feb 2009
Updated04 Jun 2010
More by this author...

Description

Custom type that outputs time formatted in the same way that the date type does. Accepts the same time formatting params that date does like for example time -> format('%T'). Parts of code borrowed from date_int. Updated to support param less use.

Sample Usage

time;
-> 15:16:29
time -> format('%H.%M');
-> 15.16
time('18:30:00') -> format('%H.%M');
-> 18.30
time('18.30') -> format('%H.%M');
-> 18.30
time('18') -> format('%H.%M');
-> 18.00
time('18.70:00') -> format('%T');
-> 19:10:00
time('18.30') -> type;
-> time

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.

 format('%T'). 
Parts of code borrowed from date_int.

Sample usage:

time;
time -> format('%H.%M');
time('18:30:00') -> format('%H.%M');
time('18') -> format('%H.%M');
time('18.70:00') -> format('%T');
time('18.30') -> format('%H.%M');
time('18.30') -> type;

*/
	local('time',
	);

	define_tag( 'oncreate',
		-opt = 'time', -copy
		);
		 self -> 'time' = (local_defined('time') ? #time | string(date -> format('%T')));
	/define_tag;
	define_tag( 'onconvert');
		return(self -> 'time');
	/define_tag;

	define_tag('format', -req = 'formatstring', -type = 'string', -copy);
		
		// convert the format string to bytes to get case sensitive comparisons
		#formatstring = bytes(#formatstring);

		(self -> 'time' -> type == 'date' ?
			self -> 'time' = string(self -> 'time' -> format('%T')));

		self -> 'time' -> replace('.', ':');
		local('time' = self -> 'time' -> split(':'));
		local('size' = #time -> size);

		select(true);
			case(#size > 2);
				return(date(-year = 2008, -month = 1, -day = 1, -hour = integer(#time -> first), -minute = integer(#time -> second), -second = integer(#time -> get(3))) -> format(#formatstring));
			case(#size == 2);
				return(date(-year = 2008, -month = 1, -day = 1, -hour = integer(#time -> first), -minute = integer(#time -> last), -second = 0) -> format(#formatstring));
			case(#size == 1);
				return(date(-year = 2008, -month = 1, -day = 1, -hour = integer(#time -> first), -minute = 0, -second = 0) -> format(#formatstring));
		/select;

	/define_tag;


/define_type;
?>

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