Time comparison ACF vs Lucee

97 views
Skip to first unread message

JD Yeiter

unread,
Feb 16, 2016, 8:04:05 AM2/16/16
to Lucee
I came across this (bug?) when I was testing my app on Lucee.  Basically, here's the code that returned false on ACF and true on Lucee:

<cfset arguments.testTime = "6:45 PM">
<cfset arguments.currentTime = "7:50 AM">
<cfif timeformat(arguments.testTime,"hh:mm tt") lt timeformat(arguments.currentTime,"hh:mm tt")>
 
<cfreturn true />
<cfelse>
 
<cfreturn false />
</cfif>




If I change the time format to "HH:mm tt", then it returns FALSE on Lucee (as it should).

I just don't know how Lucee compares time/date strings vs ACF.  I guess the question is: is this a bug or expected behavior?


-JD


Paul Klinkenberg

unread,
Feb 16, 2016, 10:08:16 AM2/16/16
to lu...@googlegroups.com
Hi JD,

Whenever you want to compare date or time elements, then make sure you are not comparing strings, but instead are comparing number or date objects.

Your current code does a string comparison "06:45 PM" lt "07:50 AM", which indeed is true. Lucee is correct.

The reason ACF did return a False value, is a weird feature on their part. What ACF does before comparing a string, is checking if it can parse the strings as a date/datetime. If it can parse them as dates, then it will do so before comparison.
The user never asked for that, it's weird, but that's the reason you are seeing differences. Lucee is cool, ACF the weird one.

If your timeFormat method had a different output, which cannot be converted back to a date/time object, ACF would have said True as well:
<cfif timeformat(arguments.testTime,"hhXXXXXmm tt"lt timeformat(arguments.currentTime,"hhXXXXXmm tt")>

The easiest thing would have been, to first convert the time objects, like so:
<cfset testTime = parseDateTime("6:45 PM")>
<cfset currentTime = parseDateTime("7:50 AM")>
<cfreturn testTime lt currentTime />

Just for the fun of it, I did some tests at cflive.net between ACF and Lucee: (code is underneath)

Coldfusion:
(2000-01-01) lt (01/01/2020) = YES
(2000-01) lt (01/01/2020) = YES
(2000) lt (01/01/2020) = YES
(200) lt (01/01/20) = YES
(200) lt (01/) = NO
(20) lt (01) = NO
(01-12-2030) lt (12/02/2000) = NO
(01-12) lt (12/02) = YES
(01-12-2) lt (12/02/2) = YES
(01-12-203) lt (12/02/200) = NO 

Lucee:
string(2000-01-01) lt (01/01/2020) = false

string(2000-01) lt (01/01/2020) = false

string(2000) lt (01/01/2020) = false

string(200) lt (01/01/20) = false

string(200) lt (01/) = false

string(20) lt (01) = false

string(01-12-2030) lt (12/02/2000) = true

string(01-12) lt (12/02) = true

string(01-12-2) lt (12/02/2) = true

string(01-12-203) lt (12/02/200) = true

<cfset d1 = "2000-01-01" />
<cfset d2 = "01/01/2020" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "2000-01" />
<cfset d2 = "01/01/2020" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "2000" />
<cfset d2 = "01/01/2020" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "200" />
<cfset d2 = "01/01/20" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "200" />
<cfset d2 = "01/" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "20" />
<cfset d2 = "01" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "01-12-2030" />
<cfset d2 = "12/02/2000" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "01-12" />
<cfset d2 = "12/02" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "01-12-2" />
<cfset d2 = "12/02/2" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>

<cfset d1 = "01-12-203" />
<cfset d2 = "12/02/200" />
<cfdump var="(#d1#) lt (#d2#) = #d1 lt d2#" /><hr>


Kind regards,

Paul Klinkenberg

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/2102f1c2-d118-4f21-a07c-f073a8d5954c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JD Yeiter

unread,
Feb 16, 2016, 10:23:32 AM2/16/16
to Lucee
Thanks Paul!

Great explanation.  

I didn't know cflive.net existed.  It should help as I port over the code.


-JD
Reply all
Reply to author
Forward
0 new messages