Skip to content

Commit

Permalink
feat: guess whether timestamp is in seconds or milliseconds (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Nov 18, 2024
1 parent 7d5f0d3 commit e812f92
Showing 1 changed file with 16 additions and 6 deletions.
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

0 comments on commit e812f92

Please sign in to comment.