From 8fa8b18fce73fa3f7d0acf1927e319d7a2d95ff7 Mon Sep 17 00:00:00 2001
From: adam-james <21064735+adam-james-v@users.noreply.github.com>
Date: Mon, 9 Jan 2023 15:10:38 -0800
Subject: [PATCH] Add processing step to the date format string so that we get
 Day of Month (#27557)

Since the frontend sends a date-style string with various differences from how Java's Date Formatter expects things,
we need to post-process some bits. The 'D' -> 'd' string replacement was missed in the post processing fn, and so in
some cases it was missed altogether, causing this bug.

Existing tests in `metabase.pulse.render.datetime-test` and `metabase.pulse.render.table-test` should already catch
this issue. Prior to the change they would fail, but they now pass after adding this PR's changes.
---
 src/metabase/pulse/render/datetime.clj | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/metabase/pulse/render/datetime.clj b/src/metabase/pulse/render/datetime.clj
index 5adb9a8d44f..cbae5e70f41 100644
--- a/src/metabase/pulse/render/datetime.clj
+++ b/src/metabase/pulse/render/datetime.clj
@@ -84,11 +84,15 @@
                                           (-> (:type/Temporal (public-settings/custom-formatting))
                                               (update-keys (fn [k] (-> k name (str/replace #"_" "-") keyword)))))
            post-process-date-style      (fn [date-style]
-                                          (cond-> (-> date-style (str/replace #"dddd" "EEEE"))
-                                            date-separator (str/replace #"/" date-separator)
-                                            abbreviate     (-> (str/replace #"MMMM" "MMM")
-                                                               (str/replace #"EEEE" "EEE")
-                                                               (str/replace #"DDD" "D"))))]
+                                          (let [conditional-changes
+                                                (cond-> (-> date-style (str/replace #"dddd" "EEEE"))
+                                                  date-separator (str/replace #"/" date-separator)
+                                                  abbreviate     (-> (str/replace #"MMMM" "MMM")
+                                                                     (str/replace #"EEEE" "EEE")
+                                                                     (str/replace #"DDD" "D")))]
+                                            (-> conditional-changes
+                                                ;; 'D' formats as Day of Year, we want Day of Month, which is  'd' (issue #27469)
+                                                (str/replace #"D" "d"))))]
        (case (:unit col)
          ;; these types have special formatting
          :minute  (reformat-temporal-str timezone-id s
@@ -119,5 +123,4 @@
 
          ;; for everything else return in this format
          (reformat-temporal-str timezone-id s (-> (or date-style "MMMM d, yyyy")
-                                                  (str/replace #"D" "d")
                                                   post-process-date-style)))))))
-- 
GitLab