From c38e4f720658375000e95ddfa8b2cb87dcb9e521 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 22 Apr 2022 22:21:36 +0200 Subject: [PATCH] helper functions --- packages/core/hap.mjs | 5 ++++- packages/core/timespan.mjs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/hap.mjs b/packages/core/hap.mjs index 44ff7ba0..b74649c6 100644 --- a/packages/core/hap.mjs +++ b/packages/core/hap.mjs @@ -1,4 +1,3 @@ - export class Hap { /* Event class, representing a value active during the timespan @@ -77,6 +76,10 @@ export class Hap { ); } + showWhole() { + return `${this.whole == undefined ? '~' : this.whole.show()}: ${this.value}`; + } + combineContext(b) { const a = this; return { ...a.context, ...b.context, locations: (a.context.locations || []).concat(b.context.locations || []) }; diff --git a/packages/core/timespan.mjs b/packages/core/timespan.mjs index 5c398da1..a55e1de8 100644 --- a/packages/core/timespan.mjs +++ b/packages/core/timespan.mjs @@ -28,6 +28,10 @@ export class TimeSpan { return spans; } + get duration() { + return this.end.sub(this.begin); + } + cycleArc() { // Shifts a timespan to one of equal duration that starts within cycle zero. // (Note that the output timespan probably does not start *at* Time 0 --