1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-25 08:19:40 +02:00

#8546 fix(logging): manage time in seconds or milliseconds (#8547)

This commit is contained in:
pibica 2023-05-04 21:41:11 +02:00 committed by GitHub
parent a062a0bfbe
commit 5d2723f4b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -49,7 +49,12 @@ export function formatTime(
if (time) {
let date = '';
if (typeof time === 'number') {
date = format(new Date(time * 1000), 'Y/MM/dd hh:mmaa');
// time is a number, so it is the number of seconds OR milliseconds since Unix Epoch (1970-01-01T00:00:00.000Z)
// we need to know if time's unit is second or millisecond
// 253402214400 is the numer of seconds between Unix Epoch and 9999-12-31T00:00:00.000Z
// if time is greater than 253402214400, then time unit cannot be second, so it is millisecond
const timestampInMilliseconds = time > 253402214400 ? time : time * 1000;
date = format(new Date(timestampInMilliseconds), 'Y/MM/dd hh:mmaa');
} else {
date = time;
}