advplyr.audiobookshelf/server/libs/jsonwebtoken/lib/timespan.js

18 lines
406 B
JavaScript
Raw Normal View History

2024-08-04 12:52:52 -05:00
const ms = require('ms')
2022-07-06 18:45:43 -05:00
module.exports = function (time, iat) {
2024-08-04 12:52:52 -05:00
var timestamp = iat || Math.floor(Date.now() / 1000)
2022-07-06 18:45:43 -05:00
if (typeof time === 'string') {
2024-08-04 12:52:52 -05:00
var milliseconds = ms(time)
2022-07-06 18:45:43 -05:00
if (typeof milliseconds === 'undefined') {
2024-08-04 12:52:52 -05:00
return
2022-07-06 18:45:43 -05:00
}
2024-08-04 12:52:52 -05:00
return Math.floor(timestamp + milliseconds / 1000)
2022-07-06 18:45:43 -05:00
} else if (typeof time === 'number') {
2024-08-04 12:52:52 -05:00
return timestamp + time
2022-07-06 18:45:43 -05:00
} else {
2024-08-04 12:52:52 -05:00
return
2022-07-06 18:45:43 -05:00
}
2024-08-04 12:52:52 -05:00
}