Minetrack/lib/time.js

35 lines
713 B
JavaScript
Raw Normal View History

const config = require('../config.json')
class TimeTracker {
2020-05-08 06:54:04 +00:00
constructor (app) {
this._app = app
this._points = []
}
newTimestamp () {
const timestamp = new Date().getTime()
this._points.push(timestamp)
if (this._points.length > TimeTracker.getMaxServerGraphDataLength()) {
this._points.shift()
}
return timestamp
}
getPointsSeconds () {
return this._points.map(value => Math.floor(value / 1000))
}
static getMaxServerGraphDataLength () {
return Math.ceil(config.serverGraphDuration / config.rates.pingAll)
}
static getMaxGraphDataLength () {
return Math.ceil(config.graphDuration / config.rates.pingAll)
}
}
module.exports = TimeTracker