The DateFormat D Mask Change
Adobe CF2021 and above changed the output of the mask ‘D’ in the DateFormat and DateTimeFormat functions. This change is not new. However, I found the Adobe documentation unclear when I tried to fix it for backwards compatibility.
Charlie Arehart has already talked about this. Adobe also added a blog post after a bug report. However, even after reading Adobe’s post, I still had two questions. Did I need to include the JAR hotfix? Also, why did their examples not match my findings?
What Changed in ACF2021+
Before the 2021 upgrade, the following code would produce:
Result: 2023-10-01
However, with ACF2021+, that same code produces:
Result: 2023-10-274
October 1, 2023 is the 274th day out of 365 days for the year. That is what the mask ‘D’ now outputs. Adobe made this change to match the underlying Java libraries’ masking.
The JVM Argument Fix
I needed to make ACF2021 backwards compatible without changing any code. To do that, I had to add a JVM argument to the server.
In my case, I use Ortus CommandBox and its ‘server.json’ definition. I added this in the ‘jvm’ section:
That is the only change that is needed. The mentioned JAR hotfix is not needed. Also, 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:
Result: 2323-10-01
What I Saw With the DD Mask
In Adobe’s example, they seem to indicate no difference between a double mask of ‘DD’ and just ‘D’ for single unit days. In other words, their example suggests that ‘DD’ returns ‘1’ instead of ’01’.
That is not what I am seeing. In my tests, the output respects the double mask and returns ’01’ as expected.
A Warning About the JVM Flag
Be aware of dragons. Adding this JVM flag to your CF app changes the behaviour of the entire JVM on your server. Therefore, it could break plugins or modules that rely on the capital ‘D’ format.
Long-Term Recommendation
Regardless, this works well as a quick fix for me. However, going forward, the code should use lowercase ‘d’ instead. That is the better long-term solution.
3 Responses to Clarifying the use of the DateFormat ‘D’ mask for ACF2021+