Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUR-14060 Setting UTC as the fallback if the user timezone is not present #415

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 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 (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()) {
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
Loading