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

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+

  • 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.
  • Charlie Arehart
    Thanks very much for the kind regards, a d sorry I missed this back in November. But it also allows me to point out that I'd brought up your observation to Adobe (about their technote still mentioning the jar), and it'ss since been removed. Again, we all still need the arg even with cf2025 and beyond (unless we want to change our code--and in my blog post I point out regex strings folks offered to help find and replace such uses of D vs d.)

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.