Thursday, October 6, 2016

More Date Masking

I'm a bit ashamed of myself. I've been a member of the ColdFusion Community for over 15 years, yet I just submitted my first bug to the BugBase yesterday. And I'm not even really sure that it's a "bug" per se; just an inconsistency in behavior of similar functions.

https://bugbase.adobe.com/index.cfm?event=bug&id=4194962
(Lucee bug added: https://luceeserver.atlassian.net/browse/LDEV-1025)

Basically, it touches on what has become a pet-peeve of mine: Date Masking. I know I've ranted about it before, but I wish that everyone could just agree on what a proper date mask was for all of the common date parts.

In the latest update to ColdFusion, Update 3, one of the things Adobe announced in the release notes was that you can now use lower- or upper-case letters in DateFormat() masking. My issue with this is that it is completely different behavior from DateTimeFormat(), which seems to make a bit more use of Java's case-sensitive SimpleDateFormat. Granted, I don't agree with Java's way of using "M" to mean "months" and "m" to mean "minutes" (I like CF's "n" minutes), but I still think the two CF functions should be consistent with each other. It's feasible that a dev would have to switch between a date format with and without a time component or have multiple types of date masks on the same page. And the natural assumption would be that the mask from one should work as the mask for the other. At least I would think so.

Last year, I got bit by this behavior when it came to the Year mask. December 29, 2015 was being displayed as 12/29/2016. ???? FYI: DateFormat(someDate,"MM/DD/YYYY") may not return the same thing as DateTimeFormat(someDate,"MM/DD/YYYY"). This is where I learned about the slight difference between a Calendar Year and a Week Year. Not to mention the fact that it will only happen at most on the last few days of a year.

And to make matters worse, we also used moment.js, which expects the year to be formatted as a capital "Y". :-/

I've never made it a secret that I'm not a fan of silent errors. And, yes, this would be an error on the developer's part for not using the proper mask, but it's an easy error to make (especially when using different masks) and even easier to completely miss.

I would like to see Adobe make the date formatting functions be a bit more consistent with each other.


THANK YOU, TRYCF.COM! http://trycf.com/gist/78a374effc62c05330cd33030da265cd/acf2016?theme=monokai

Adobe ColdFusion 2016
Adobe ColdFusion 10

And Lucee just gets wonky with its CFMXish behavior of kinda passing through masks it can't interpret.
Lucee 4.5

No comments:

Post a Comment