Skip to content

Commit

Permalink
date conversion fixes between local and utc ts
Browse files Browse the repository at this point in the history
  • Loading branch information
sebadob committed Sep 26, 2023
1 parent d07f2ca commit 05b59f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/admin/users/UserInfo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
let timer;
let language = user.language.toUpperCase();
let limitLifetime = !!user.user_expires;
let userExpires = limitLifetime ? formatDateToDateInput(new Date(user.user_expires * 1000)) : undefined;
let userExpires = limitLifetime ? formatDateFromTs(user.user_expires, true) : undefined;
let allRoles = [];
globalRolesNames.subscribe(rls => {
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ export const formatUtcTsFromDateInput = inputDate => {
if (isNaN(d)) {
return;
}
const tzDiff = -new Date().getTimezoneOffset() * 60;
return d / 1000 + tzDiff;
return d / 1000;
}

export const formatDateFromTs = ts => {
export const formatDateFromTs = (ts, fmtIso) => {
const utcOffsetMinutes = -new Date().getTimezoneOffset();
const d = new Date((ts + utcOffsetMinutes * 60) * 1000);

Expand All @@ -179,6 +178,9 @@ export const formatDateFromTs = ts => {
sc = '0' + sc;
}

if (fmtIso) {
return `${yyyy}-${mm}-${dd}T${hr}:${mn}:${sc}`;
}
return `${yyyy}/${mm}/${dd} ${hr}:${mn}:${sc}`;
}

Expand Down

0 comments on commit 05b59f2

Please sign in to comment.