blob: 4f19986b2ace820efef85816b5fd864220a1573c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
* timer.js
* Part of Pointless Viewer, a Beamer presentation viewer
* Copyright 2018 Pacien TRAN-GIRARD
* License: GNU GPL v3
*/
"use strict";
class Timer {
constructor(window) {
this.display = window.document.getElementById("timer");
this.startTime = null;
this._setDisplay(0);
}
start() {
if (this.startTime != null) return;
this.startTime = Date.now();
var self = this;
setInterval(function() {
self._runTimer();
}, 1000);
}
_runTimer() {
var timeDelta = Math.floor((Date.now() - this.startTime) / 1000);
this._setDisplay(timeDelta);
}
_setDisplay(seconds) {
var dateObj = new Date(null);
dateObj.setSeconds(seconds);
this.display.textContent = dateObj.toISOString().substr(11, 8);
}
}
|