Lasso Soft Inc. > Home

[lp_date_stringToOffset]

Linklp_date_stringToOffset
AuthorBil Corry
CategoryDate
Version8.x
LicensePublic Domain
Posted02 Mar 2006
Updated02 Mar 2006
More by this author...

Description

Returns a standardize timezone string (e.g. +0100) given a timezone offset string. Optionally can return a map of the hours and minutes.

Requires [lp_string_getnumeric] [lp_string_pad]

Sample Usage

	var:'test' = (: '-0800', '-1445', '1445', '+0100', '0', '', null, '-', '9:00', '+12', '-5');
	iterate:$test, local:'t';
		#t ' ' (lp_date_stringtoOffset:#t);'
'; /iterate; '
'; iterate:$test, local:'t'; #t ' ' (lp_date_stringtoOffset:#t,-map);'
'; /iterate;

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:'lp_date_stringToOffset',
	-description='Returns a standardize timezone string (e.g. +0100) given a timezone offset string. Optionally can return a map of the hours and minutes.',
	-priority='replace',
	-required='timezone_offset', -copy,
	-optional='map', -copy;

	// Note: I use a workaround due to Lasso 8.1 bug where (integer: -08) == 0 instead of -8
	// So this is far more complicated that it should be :(

	if: local_defined:'map';
		#map = true;
	else;
		local:'map' = false;
	/if;

	#timezone_offset = string: #timezone_offset;

	local:'direction' = 1;
	local:'sign' = '+';
	if: #timezone_offset->(contains:'-');
		#direction = -1;
		#sign = '-';
	/if;

	// default at UTC/GMT
	local:'hours' = 0;
	local:'minutes' = 0;

	local:'offset' = lp_string_getnumeric: #timezone_offset;

	if: #offset->size == 0;
		// go with default
	else: #offset->size <= 2; // e.g. 5, 10, 3
		#offset->(removeleading:'0');
		#hours = #direction * (integer: #offset);
	else: #offset->size == 3;  // e.g. 500, 800, 300
		#hours = #direction * (integer: #offset->(substring: 1,1));
		#minutes = (integer: #offset->(substring: 2,2));
	else: #offset->size == 4; // e.g. 0500, 1300, 0130
		#hours = #direction * (integer: #offset->(substring: 1,2));
		#minutes = (integer: #offset->(substring: 3,2));
	else;
		fail: -1,'Offset not recognized.';
	/if;

	if: #map;
		return: (map: 'hours' = #hours, 'minutes' = #minutes);
	else;

		if: #hours == 0 && #minutes == 0;
			#sign = '+';
		/if;

		return: #sign (lp_string_pad: (math_abs:#hours), 2) (lp_string_pad: #minutes, 2);

	/if;

/define_tag;

]

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