From 1a0dff40817bfed6fb38fa22e3b485d6f37b4878 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 28 Mar 2024 05:47:50 +0100 Subject: [PATCH] add some hap methods for time introspection --- packages/core/hap.mjs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/core/hap.mjs b/packages/core/hap.mjs index ab5f0c97..7f35ce55 100644 --- a/packages/core/hap.mjs +++ b/packages/core/hap.mjs @@ -49,6 +49,24 @@ export class Hap { return this.whole.begin.add(this.duration); } + isActive(currentTime) { + return this.whole.begin <= currentTime && this.endClipped > currentTime; + } + + isInPast(currentTime) { + return currentTime > this.endClipped; + } + isInNearPast(margin, currentTime) { + return currentTime - margin <= this.endClipped; + } + + isInFuture(currentTime) { + return currentTime < this.whole.begin; + } + isInNearFuture(margin, currentTime) { + return currentTime < this.whole.begin && currentTime > this.whole.begin - margin; + } + wholeOrPart() { return this.whole ? this.whole : this.part; }