Clarifying the use of the DateFormat ‘D’ mask for ACF2021+

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:

Result: 2023-10-01

However, with ACF2021+, that same code:
Result: 2023-10-274

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:

Result: 2323-10-01

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.

2 Responses to Clarifying the use of the DateFormat ‘D’ mask for ACF2021+

  • Charlie Arehart
    Hey, Evagoras. Thanks for the post and the shout-out. While the change is new with cf2021, that was indeed now 4 years ago this month. My how time flies! And to clarify, it was in fact cf2021 update 1 which included the fix such that the JAR was no longer needed, though the jvm arg was and (as you note) STILL IS needed to revert the behavior. (We can wish they'd have instead reverted the behavior by default instead, but they did not.) FWIW, I had modified my post back then (see the 3rd paragraph), but it's true that the Adobe technote you link to still mentions need of the jar. That's because it was written in the weeks after cf2021 came out and before update 1 included the fix to support that arg. I have just brought that to their attention. Since resources like this and others even from Adobe may still point to that technote, it should be updated to clarify the jar is no longer necessary--while the jvm arg still is. Good on you for adding clarification for Commandbox users, on how to add such a jvm arg.
    • Evagoras Charalambous
      Charlie, I always treat your blog as the source of truth whenever I see contradicting resources. It's great that you go back and edit your older posts and make sure that, regardless of how old a post is, they are always up to date. Your work is very much appreciated sir.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.