diff --git a/src/dateUtils.js b/src/dateUtils.js index cbe4cef..7d2f3e6 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 (typeof ProcessMaker !== "undefined" && 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) { + if (typeof ProcessMaker !== "undefined" && 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()); }