[tzconvert]

Description

Link: [tzconvert]
Author: Jolle Carlestam
Category: Date
Version: 9.x
License: Public Domain
Posted: Aug. 31, 2011
Updated: Jan. 01, 0001
More by this author...

Method to set datetime values to specific timezones. Can also convert datetime values from the input timezone to the output.

NOTE Requires Lasso 9.1 or a late SVN patched version of Lasso 9.0 due to changes/fixes made to the date type

Parameters

-date date, required
-tz_in string, optional
-tz_out string, optional
-format string, optional
-convert boolean, optional

Sample Usage

tzconvert(date, -tz_out = 'Australia/Sydney')
'<br>'
tzconvert(date_localtogmt(date),-tz_in = 'GMT', -tz_out = 'Australia/Sydney', -convert)
'<br>'
tzconvert(date, -tz_out = 'Australia/Sydney', -format = '%Q %T V', -convert)
'<br>'
tzconvert(date('2011-12-13 ' + date -> time), -format = '%Q %T V', -tz_out = 'Australia/Sydney', -convert)
'<br>'
tzconvert(date('2011-12-13 ' + date -> time), -format = '%-d %b %Y %H:%M:%S V', -tz_out = 'Australia/Brisbane', -convert)
'<br>'
tzconvert(date('2011-12-13 ' + date -> time), -format = '%-d %b %Y %H:%M:%S V', -tz_out = 'Australia/Darwin', -convert)
						

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
43
44
45
46
47
48
49
50
51
52
<?LassoScript
/**!
tzconvert

Method to set datetime values to specific timezones. Can also convert datetime values from the input timezone to the output.

Params are:
date		Input date, required
-tz_in		What timezone the input date is to be treated as. If not set will use the timezone from the input date
-tz_out		What timezone the output date should be set to. Defaults to GMT
-format		Format used for the output date. Defaults to %Q %T (2011-08-26 12:58:27)
-convert	If true will convert the input date to a value corresponding to the output timezone. Defaults to false

NOTE Requires Lasso 9.1 or a late SVN patched version of Lasso 9.0 due to changes/fixes made to the date type


2011-08-31	JC	First version

**/
define tzconvert(
	date::date,
	input_timezone::string = #date -> timezone,
	output_timezone::string = 'GMT',
	format::string = '%Q %T',
	convert::boolean = false
) => {

	local(_date = date(#date -> format('%q')))
	#_date -> timezone = #input_timezone
	local(zoneoffin = #_date -> ascopy -> zoneoffset)
	#zoneoffin += #_date -> ascopy -> dstoffset
	#_date -> timezone = #output_timezone
	local(zoneoffout = #_date -> ascopy -> zoneoffset)
	#zoneoffout += #_date -> ascopy -> dstoffset

	#convert ? #_date -> add(-millisecond = (#zoneoffout - #zoneoffin))

	#_date -> setformat(#format)

	return #_date

}

define tzconvert(
	date::date, // input date
	-tz_in::string = #date -> timezone,
	-tz_out::string = 'GMT',
	-format::string = '%Q %T',
	-convert::boolean = false
) => tzconvert(#date, #tz_in, #tz_out, #format, #convert)

?>

 

Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net