Conditional run only in Lucee?

My ACF 11 server complains about syntax, even when wrapped in a conditional to NOT run unless on a Lucee server (if I’m doing this right?). Initially I only had the outer cfif tag, but added the scripted if recently as well. Still ACF complains that the “DAY function takes 1 parameter”. This is just a quick file I run to remind myself of commonly used Date/Time functions. Runs fine on Lucee. Nothing super important, but I’d love to know what I got wrong:

<cfif SERVER.ColdFusion.ProductName EQ "Lucee">
	<cfscript>
	if (SERVER.ColdFusion.ProductName EQ "Lucee") {
		dump(
			var:now().getTime()
			,label:"var:now().getTime() = time passed in ms since 1/1/1970 00:00:00 UTC "
		);
		
		writeOutput("<hr>");
		writeOutput("dump(getTimeZone());");
		dump(getTimeZone());
		
		writeOutput("<hr>");
		// example04
		
		writeOutput("<pre>	unix0=now()  //parseDateTime('Thursday, January 1, 1970 0:00:00 AM UTC');
		setTimeZone('EST'); // Eastern
		dump(unix0);
		setTimeZone('MST'); // Mountain 
		dump(unix0);
		setTimeZone('CST'); // Central
		dump(unix0);
		setTimeZone('PST'); // Pacific 
		dump(unix0);</pre>");
	
		unix0=now();  //parseDateTime('Thursday, January 1, 1970 0:00:00 AM UTC');
		setTimeZone("EST"); // Eastern
		dump(unix0);
		setTimeZone("MST"); // Mountain 
		dump(unix0);
		setTimeZone("CST"); // Central
		dump(unix0);
		setTimeZone("PST"); // Pacific 
		dump(unix0);
		
		writeOutput("<hr>");
		// example05
		
		dump(dateTimeFormat(unix0,"full","PST")); // Pacific
		dump(dateTimeFormat(unix0,"full","MST")); // Mountain
		dump(dateTimeFormat(unix0,"full","CST")); // Central
		dump(dateTimeFormat(unix0,"full","EST")); // Eastern 
		
		writeOutput("<hr>");
		// example06
		
		dump(day(unix0,"PST")); // Pacific/US
		dump(day(unix0,"CET")); // Central Europe
		
		
		writeOutput("<hr>");
		// example07
		getPageContext().setTimestampWithTSOffset(true);
		dump(unix0);
		
		writeOutput("<hr>");
		// example09
		
		nbr=123.456;
		dump(lsCurrencyFormat(nbr,"international","de_CH"));
		dump(lsCurrencyFormat(nbr,"international","en_US"));
		dump(dateTimeFormat(unix0,'long','US/Hawaii'));
		dump(dateTimeFormat(unix0,'long','Pacific/Tahiti'));
	
		writeOutput("<hr>");
		// example10
		
		dump(unix0);
		dump(dateConvert("local2Utc",unix0));
		t=dateConvert("local2Utc",unix0);
		t=dateConvert("local2Utc",t);
		dump(t);
	}
	</cfscript>
	
	<!--- example08 --->
	<cfset qry = QueryNew('currTime')>
	<cfset temp=QueryAddRow(qry, 1)>
	<cfset temp=QuerySetCell(qry, "currTime", "ValueA1", 1)>

	<cfquery dbtype="query" name="qry">
		select '#DateTimeFormat(now(), "yyyy-mm-dd HH:nn:ss")#' as blah
		from qry
	</cfquery>
	<cfdump var="#qry#">
	
<cfelse>
	<p>Lucee Only Functions not run in CF</p>
</cfif>

Adobe CF 11 still needs to compile the CFML into bytecode, so if it’s not compatible with CF11’s parser, it won’t compile. The only way around this is to create two CFCs or CFMs and create/include the appropriate one for the current engine. Since CFML is JIT compiled, that will prevent the wrong engine from “seeing” the wrong code. (this does preclude any sort of process which pre-compiles all your code)

1 Like

you can use evaluate() (OMG they killed Kenny!) like I had to do here, as BIFs don’t accept argumentCollections

Ya, I figured that might be what’s happening. Thanks!

Interesting! That may come in handy! :upside_down_face: