From 42836792976eed0c4bdef739a5377d1804caba96 Mon Sep 17 00:00:00 2001 From: Teisha McRae Date: Mon, 28 Sep 2026 14:55:39 -0400 Subject: [PATCH] Convert PHP date formats for user config This change adds helpers to translate PHP datetime/calendar tokens into Moment-compatible formats and applies them when loading user config and the task page user object. It prevents legacy Blade-generated format strings from being used directly by Moment and keeps date rendering consistent across the app. --- resources/js/next/config/user.js | 38 ++++++++++++++++++++++---- resources/js/vite/tasks/loaderTasks.js | 7 +++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/resources/js/next/config/user.js b/resources/js/next/config/user.js index 85e26880c2..74ad587ff3 100644 --- a/resources/js/next/config/user.js +++ b/resources/js/next/config/user.js @@ -1,6 +1,33 @@ import { getGlobalVariable, setGlobalPMVariables } from "../globalVariables"; import datetime_format from "../../data/datetime_formats.json"; +// Profile settings store PHP date tokens; Moment uses a different token set. +export const momentFormatsFor = (phpFormat) => { + const match = datetime_format.find((value) => value.format === phpFormat); + if (!match) { + return null; + } + return { + datetime_format: match.momentFormat, + calendar_format: match.calendarFormat, + }; +}; + +export const withMomentDateFormats = (user) => { + if (!user || typeof user !== "object") { + return user; + } + const formats = momentFormatsFor(user.datetime_format); + if (!formats) { + return user; + } + return { + ...user, + datetime_format: formats.datetime_format, + calendar_format: formats.calendar_format, + }; +}; + export default () => { const moment = getGlobalVariable("moment"); const userID = document.head.querySelector("meta[name=\"user-id\"]"); @@ -25,12 +52,11 @@ export default () => { avatar: userAvatar?.content, }; - datetime_format.forEach((value) => { - if (formatDate.content === value.format) { - user.datetime_format = value.momentFormat; - user.calendar_format = value.calendarFormat; - } - }); + const formats = momentFormatsFor(formatDate?.content); + if (formats) { + user.datetime_format = formats.datetime_format; + user.calendar_format = formats.calendar_format; + } if (user) { moment.tz.setDefault(user.timezone); diff --git a/resources/js/vite/tasks/loaderTasks.js b/resources/js/vite/tasks/loaderTasks.js index f2768631fe..07c7546fd1 100644 --- a/resources/js/vite/tasks/loaderTasks.js +++ b/resources/js/vite/tasks/loaderTasks.js @@ -1,5 +1,6 @@ import "../../../js/vite/bootstrap-globals.js"; import { setupMain } from "../../../js/next/setupMain"; +import { withMomentDateFormats } from "../../next/config/user"; import vueFormElements from "../../../js/next/libraries/vueFormElements"; import modelerInspector from "../../../js/next/libraries/modelerInspector"; import modeler from "../../../js/next/modeler"; @@ -19,7 +20,9 @@ window.ProcessMaker.defaultColumns = window.temporal.defaultColumns; window.ProcessMaker.isDefaultColumns = window.temporal.isDefaultColumns; window.ProcessMaker.userConfiguration = window.temporal.userConfiguration; window.ProcessMaker.showOldTaskScreen = window.temporal.showOldTaskScreen; -window.ProcessMaker.user = window.temporal.user; +// Blade user stores a PHP datetime format; convert it before Moment formatters read it. +const pageUser = withMomentDateFormats(window.temporal.user); +window.ProcessMaker.user = pageUser; window.ProcessMaker.selectedProcess = window.temporal.selectedProcess; window.ProcessMaker.defaultSavedSearchId = window.temporal.defaultSavedSearchId; window.ProcessMaker.isTceCustomization = window.temporal.isTceCustomization; @@ -30,6 +33,6 @@ window.ProcessMaker.packages = window.temporal.packages; // Legacy Mix keys (lowercase "m") used by TasksMixin / ParticipantHomeScreen window.Processmaker = window.Processmaker || {}; window.Processmaker.defaultColumns = window.temporal.defaultColumns; -window.Processmaker.user = window.temporal.user; +window.Processmaker.user = pageUser; window.Processmaker.selectedProcess = window.temporal.selectedProcess; window.Processmaker.defaultSavedSearchId = window.temporal.defaultSavedSearchId;