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

pull/8905/head
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
1 changed files with 6 additions and 1 deletions

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;
}