dates are millis

This commit is contained in:
cv
2021-04-12 22:21:18 +02:00
parent 19bb1904f6
commit 023c8c446e
10 changed files with 61 additions and 54 deletions
+2 -5
View File
@@ -44,17 +44,14 @@ class EventTimer extends Timer {
loadEvent(eventIndex) {
// set event specific
const e = this._eventList[eventIndex];
const start =
e.timeStart == null || e.timeStart === '' ? 0 : new Date(e.timeStart);
const end =
e.timeEnd == null || e.timeEnd === '' ? 0 : new Date(e.timeEnd);
const start = e.timeStart == null || e.timeStart === '' ? 0 : e.timeStart;
const end = e.timeEnd == null || e.timeEnd === '' ? 0 : e.timeEnd;
this._resetTimers();
this.duration = end - start;
this.current = this.duration;
this.selectedEvent = eventIndex;
this.selectedEventId = e.id;
}
print() {
+16 -4
View File
@@ -20,7 +20,7 @@ class Timer {
// call setup separately
setupWithSeconds(seconds, autoStart = false) {
// aux
const now = new Date().getTime();
const now = this._getCurrentTime();
// populate targets
this.duration = seconds * 1000;
@@ -42,7 +42,7 @@ class Timer {
// update()
update() {
// get current time
const now = new Date().getTime();
const now = this._getCurrentTime();
// check playstate
switch (this.state) {
@@ -72,7 +72,18 @@ class Timer {
return Math.floor(Math.max(millis * 0.001), 0);
}
// get current time in epoc
_getCurrentTime() {
// date today at midnight
let now = new Date();
let midnight = new Date(now).setHours(0, 0, 0);
// return diffence
return now - midnight;
}
_getExpectedFinish() {
if (this._finishAt == null) return null;
return this._finishAt + (this._pausedInterval + this._pausedTotal);
}
@@ -88,6 +99,7 @@ class Timer {
// getObject
getObject() {
this.update();
return {
currentSeconds: Timer.toSeconds(this.current),
expectedFinish: this._getExpectedFinish(),
@@ -111,7 +123,7 @@ class Timer {
// do we need to change
if (this.state === 'start') return;
else if (this.state === 'stop') {
const now = new Date().getTime();
const now = this._getCurrentTime();
this._startedAt = now;
this._finishAt = now + this.duration;
} else {
@@ -130,7 +142,7 @@ class Timer {
if (this.state === 'pause') return;
// update pause time
this._pausedAt = new Date().getTime();
this._pausedAt = this._getCurrentTime();
// change state
this.state = 'pause';