Skip to content

Commit

Permalink
FOUR-14060 Setting UTC as the fallback if the user timezone is not pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
josechirivella committed Feb 6, 2024
1 parent ef5c60d commit 1ad220c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/dateUtils.js
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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());
}
Expand Down

0 comments on commit 1ad220c

Please sign in to comment.