Adobe CF2021 and above has changed the output of the mask ‘D’ in the DateFormat and DateTimeFormat functions. Although this is not new, I found the Adobe documentation unclear on how to fix that for backwards compatibility.
Charlie Arehart has already talked about this, and Adobe has added a blog post following a bug report. However, even after reading Adobe’s post I still wasn’t sure if I needed to include the JAR hotfix or not, plus their examples were not matching my findings.
Before the 2021 upgrade, the following code would produce:
However, with ACF2021+, that same code:
October 1, 2023 is the 274th day out of 365 days for the year, and that’s what the mask ‘D’ now outputs; a change that was done to match the underlying Java libraries’ masking.
I needed to make ACF2021 backwards compatible without any code changes. What is needed is to add a JVM argument to the server. In my case I am using Ortus CommandBox and their ‘server.json’ definition. I added this in the ‘jvm’ section:
That’s the only change that is needed; the mentioned JAR hotfix is not needed. Omitting that setting has the same effect as setting it to ‘false’. After restarting the server and running the same code as above, the result now becomes:
In their example they seem to indicate that there is no difference between a double mask of ‘DD’ and just ‘D’ for single unit days, i.e. ‘DD’ returns ‘1’ instead of ’01’. That is not what I am seeing though; the output respects the double mask and returns ’01’ as expected.
Be aware of dragons: adding this JVM flag to your CF app will result in the entire JVM on your server changing behaviour, which could potentially break any plugins or modules which rely on the capital ‘D’ format.
Regardless, this is great as a quick fix for me, but going forward the code should be changed to use lowercase ‘d’ instead – that’s a better long-term solution.