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

feat: guess whether timestamp is in seconds or milliseconds #456

Merged
merged 2 commits into from
Nov 18, 2024
Merged
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
22 changes: 16 additions & 6 deletions views/scan.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,25 @@
const value = item[column]
let wrapperEl = null

if (Number.isInteger(value) && value >= 0) {
if (Number.isInteger(value)) {
let dateValue
try {
dateValue = new Date(value).toISOString()
} catch (error) {
dateValue = error.message
if (value >= 10000000000) { // 11 digits - assume date format in milliseconds
const date = new Date(value)
if (!isNaN(date)) {
dateValue = `${date.toISOString()} (assumed milliseconds since epoch)`
}
} else if (value >= 100000000) { // 9 digits - assume date format in seconds
const date = new Date(value * 1000)
if (!isNaN(date)) {
dateValue = `${date.toISOString()} (assumed seconds since epoch)`
}
}

wrapperEl = $('<abbr data-toggle="tooltip" data-placement="top" title="' + dateValue + '"></abbr>')
if (dateValue) {
wrapperEl = $('<abbr data-toggle="tooltip" data-placement="top" title="' + dateValue + '"></abbr>')
} else {
wrapperEl = $('<div class="preformatted"></div>')
}
} else {
wrapperEl = $('<div class="preformatted"></div>')
}
Expand Down