Last active
April 5, 2016 17:13
-
-
Save roryl/6a9839d7d9cbd52636afc35844e1aa3f to your computer and use it in GitHub Desktop.
Lucee Date Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.timezone = "UTC"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myDate = createDate(2016, 4, 5); | |
writeDump(myDate); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myDate = createDateTime(2016, 4, 5, 0, 0, 0); | |
writeDump(myDate); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
myDate = createDate(2016, 4, 5); | |
myDate2 = createDate(2016, 4, 7); | |
otherDate = createDate(2016, 4, 5); | |
echo("myDate should be before myDate2: #myDate.compare(myDate2)# <br />"); | |
echo("myDate2 should be after myDate: #myDate2.compare(myDate)# <br />"); | |
echo("myDate should be equal to otherDate: #myDate.compare(otherDate)# <br />"); | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
setTimezone("UTC"); | |
params = [ | |
{sqltype:'timestamp', value:now()} | |
]; | |
writeDump(params); | |
writeDump(dateTimeFormat(now(), "medium")); | |
//Clear out any previous entries in the table | |
query name="truncate" datasource="luceebook" { | |
echo("truncate dates"); | |
} | |
// //Insert a record to save our date | |
query name="date" datasource="luceebook" params="#params#"{ | |
// echo("SET @@session.time_zone='+00:00';"); | |
echo("INSERT INTO dates (date) values (?)"); | |
} | |
//Insert a record to save our date | |
// query name="date" datasource="luceebook" { | |
// // echo("SET @@session.time_zone='+00:00';"); | |
// echo("INSERT INTO dates (date) values ({ts '2016-04-05 15:55:31'})"); | |
// } | |
// query name="set" datasource="luceebook" { | |
// echo("SET @@session.time_zone='+00:00';"); | |
// } | |
//Query the record, it should return in UTC | |
query name="get" datasource="luceebook" { | |
// echo("SET @@session.time_zone='+00:00';"); | |
echo("SELECT * FROM dates LIMIT 0,1"); | |
} | |
writeDump(get); | |
writeDump(get.date[1]); | |
writeDump(dateTimeFormat(get.date[1], "medium", "PST")); //But we can output into any other time zone | |
writeDump(dateTimeFormat(get.timestamp[1], "medium", "PST")); //But we can output into any other time zone | |
setting showdebugoutput="true"; | |
</cfscript> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE luceebook; | |
CREATE TABLE `dates` ( | |
`date` DATETIME NULL DEFAULT NULL, | |
`timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* My xUnit Test | |
*/ | |
component extends="testbox.system.BaseSpec"{ | |
/*********************************** LIFE CYCLE Methods ***********************************/ | |
// executes before all test cases | |
function beforeTests(){ | |
} | |
// executes after all test cases | |
function afterTests(){ | |
} | |
// executes before every test case | |
function setup( currentMethod ){ | |
} | |
// executes after every test case | |
function teardown( currentMethod ){ | |
} | |
/*********************************** TEST CASES BELOW ***********************************/ | |
// Remember that test cases MUST start or end with the keyword 'test' | |
function checkAllSyntaxTest(){ | |
var files = directoryList(""); | |
for(file IN files){ | |
if(file CONTAINS ".cfm"){ | |
include template="#getFileFromPath(file)#"; | |
} | |
} | |
} | |
function queryTest(){ | |
include template="date_insert.cfm"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
setTimezone("America/New_York"); //Set a timezone for this request | |
myDate = now(); //Set the current time to now | |
writeDump(myDate); | |
writeDump(dateTimeFormat(myDate, "medium", "PST")); //But we can output into any other time zone | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment