DEV Community

James Moberg
James Moberg

Posted on

1

ColdFusion timeFormat Conversion Testing

I was prepping some tests for the awesome Lucee Spreadsheet library and came across an issue when one of my ID strings 9A was autocast as a time 09:00:00. I wasn't expecting this to happen as it didn't seem like a valid date/time string to me. I thought this could be easily fixed by adding a space 9 A and it was still converted to a time. How about multiple spaces 9 A... nope, it's still a valid time string?

Has anyone reviewed what valid and invalid strings the TimeFormat() tag can accept? I get different results when using Adobe ColdFusion versus Lucee... and that's a problem IMHO, but is it a bug or feature?

Adobe ColdFusion 2016 / 2018 Results:

"9" = NO "00:00:00.000"
"9A" = YES "09:00:00.000"
"9p" = YES "21:00:00.000"
"9#Chr(32)##Chr(32)##Chr(32)#A " = YES "09:00:00.000"
" 9 A " = YES "09:00:00.000"
"23" = NO "00:00:00.000"
"15.4" = YES "09:36:00.000"
Enter fullscreen mode Exit fullscreen mode

Lucee 5 Results:

"9" = false "00:00:00.000"
"9A" = false "ERROR"
"9p" = false "ERROR"
"9#Chr(32)##Chr(32)##Chr(32)#A " = false "ERROR"
" 9 A " = false "ERROR"
"23" = false "00:00:00.000"
"15.4" = true "00:00:00.000"
Enter fullscreen mode Exit fullscreen mode

Source Code

<!--- 20200827 Adobe ColdFusion TimeFormat Bug?
When dumping data to Excel, some strings are incorrectly autocast as date/time values.
Blog: https://dev.to/gamesover/coldfusion-timeformat-conversion-testing-3m81
TryCF Lucee: https://www.trycf.com/gist/923f645b3944b7315c22ac693c17e94b/lucee5
TryCF ACF2016: https://www.trycf.com/gist/923f645b3944b7315c22ac693c17e94b/acf2016
TryCF ACF2018: https://www.trycf.com/gist/923f645b3944b7315c22ac693c17e94b/acf2018
--->
<cfset tests = ["9", "9A", "9p", "9#CHR(32)##CHR(32)##CHR(32)#A ", " 9 A ", "23", "15.4"]>
<cfoutput>
<cfloop array="#Tests#" index="thisTest">
<div>"#thisTest#" = #isValid("time", thisTest)#
<cftry>
"#TimeFormat(thisTest, 'HH:mm:ss.lll')#"
<cfcatch>ERROR"</cfcatch>
</cftry>
</div>
</cfloop>
</cfoutput>

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay