mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 03:43:50 +00:00
dates are millis
This commit is contained in:
@@ -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
@@ -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';
|
||||
|
||||
+26
-16
@@ -1,54 +1,64 @@
|
||||
[
|
||||
{
|
||||
"id":"5ce39a29-a70c-426a-9ce2-f97782049c71",
|
||||
"id":"xxxxx0",
|
||||
"order": 0,
|
||||
"timerDuration": 5,
|
||||
"duration": 300000,
|
||||
"type": "delay"
|
||||
},
|
||||
{
|
||||
"id": "5ce39a29-a70c-426a-9ce2-f97782049c72",
|
||||
"id":"xxxxx1",
|
||||
"order": 1,
|
||||
"title": "Is the internet a fad?",
|
||||
"subtitle": "It is",
|
||||
"presenter": "Carlos Valente",
|
||||
"timeStart": "2020-04-09T11:25:43.511Z",
|
||||
"timeEnd": "2020-04-09T12:25:43.511Z",
|
||||
"timeStart": 32400000,
|
||||
"timeEnd": 34200000,
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"id":"5ce39a29-a70c-426a-9ce2-f97782049c73",
|
||||
"id":"xxxxx2",
|
||||
"order": 2,
|
||||
"timerDuration": 25,
|
||||
"duration": 1500000,
|
||||
"type": "delay"
|
||||
},
|
||||
{
|
||||
"id": "5ce39a29-a70c-426a-9ce2-f97782049c74",
|
||||
"id":"xxxxx3",
|
||||
"order": 3,
|
||||
"title": "Is reddit a dictatorship?",
|
||||
"subtitle": "It is",
|
||||
"presenter": "Carlos Valente",
|
||||
"timeStart": "2020-04-09T13:25:43.511Z",
|
||||
"timeEnd": "2020-04-09T14:25:43.511Z",
|
||||
"timeStart": 34200000,
|
||||
"timeEnd": 36000000,
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"id": "5ce39a29-a70c-426a-9ce2-f97782049c75",
|
||||
"id":"xxxxx4",
|
||||
"order": 4,
|
||||
"title": "Out of words",
|
||||
"subtitle": "",
|
||||
"presenter": "Carlos Valente",
|
||||
"timeStart": "2020-04-09T15:25:43.511Z",
|
||||
"timeEnd": "2020-04-09T16:25:43.511Z",
|
||||
"timeStart": 36000000,
|
||||
"timeEnd": 39600000,
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"id": "5ce39a29-a70c-426a-9ce2-f97782049c76",
|
||||
"id":"xxxxx5",
|
||||
"order": 5,
|
||||
"title": "Really",
|
||||
"subtitle": "",
|
||||
"presenter": "Carlos Valente",
|
||||
"timeStart": "2020-04-09T17:25:43.511Z",
|
||||
"timeEnd": "2020-04-09T18:25:43.511Z",
|
||||
"timeStart": 39600000,
|
||||
"timeEnd": 41400000,
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"id":"xxxxx6",
|
||||
"order": 6,
|
||||
"title": "...",
|
||||
"subtitle": "",
|
||||
"presenter": "Carlos Valente",
|
||||
"timeStart": null,
|
||||
"timeEnd": null,
|
||||
"type": "event"
|
||||
}
|
||||
]
|
||||
@@ -11,7 +11,7 @@ const event = {
|
||||
|
||||
const delay = {
|
||||
order: 0,
|
||||
timerDuration: 0,
|
||||
duration: 0,
|
||||
type: 'delay',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user