From 1ad220cb51d5cb9ece8686a50bb409332e09d03c Mon Sep 17 00:00:00 2001 From: Jose Chirivella Date: Tue, 6 Feb 2024 16:50:01 -0600 Subject: [PATCH] FOUR-14060 Setting UTC as the fallback if the user timezone is not present --- src/dateUtils.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/dateUtils.js b/src/dateUtils.js index cbe4cef5..318f60b6 100644 --- a/src/dateUtils.js +++ b/src/dateUtils.js @@ -1,34 +1,34 @@ -/* global ProcessMaker*/ -import moment from 'moment-timezone'; +/* global ProcessMaker */ +import moment from "moment-timezone"; -moment.tz.setDefault(getTimezone()) +moment.tz.setDefault(getTimezone()); const startsWithNumbers = /^\d{4}-/; function getProcessMakerUserValue(key) { - if (typeof ProcessMaker !== 'undefined' && ProcessMaker.user) { + if (ProcessMaker?.user) { return ProcessMaker.user[key]; } } export function getTimezone() { - return getProcessMakerUserValue('timezone') || moment.tz.guess(); + return getProcessMakerUserValue("timezone") || "UTC"; } export function getLang() { - return getProcessMakerUserValue('lang') || 'en'; + return getProcessMakerUserValue("lang") || "en"; } export function getUserDateFormat() { - if (typeof ProcessMaker !== 'undefined' && ProcessMaker.user && ProcessMaker.user.datetime_format) { - return ProcessMaker.user.datetime_format.replace(/[\sHh:msaAzZ]/g, ''); + if (ProcessMaker?.user?.datetime_format) { + return ProcessMaker.user.datetime_format.replace(/[\sHh:msaAzZ]/g, ""); } - return 'MM/DD/YYYY'; + return "MM/DD/YYYY"; } export function getUserDateTimeFormat() { - return getProcessMakerUserValue('datetime_format') || 'MM/DD/YYYY h:mm A'; + return getProcessMakerUserValue("datetime_format") || "MM/DD/YYYY h:mm A"; } export function isValidDate(date, format = getUserDateFormat()) { @@ -43,12 +43,12 @@ export function formatIfDate(string) { return string; } - d = moment(string, 'YYYY-MM-DDTHH:mm:ss.SSSZ', true); + d = moment(string, "YYYY-MM-DDTHH:mm:ss.SSSZ", true); if (d.isValid()) { return d.format(getUserDateTimeFormat()); } - - d = moment(string, 'YYYY-MM-DD', true); + + d = moment(string, "YYYY-MM-DD", true); if (d.isValid()) { return d.format(getUserDateFormat()); }