Skip to content

Commit d739b2f

Browse files
committed
[rules] Rule Builder: Replace parse-duration with JS-Joda in TimingStateOperation
This removes dependency on parse-duration. Signed-off-by: Florian Hotze <[email protected]>
1 parent 9bd2cfa commit d739b2f

5 files changed

+12
-28
lines changed

package-lock.json

+1-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
},
2929
"dependencies": {
3030
"@js-joda/core": "^5.6.4",
31-
"@js-joda/timezone": "^2.21.2",
32-
"parse-duration": "^0.1.1"
31+
"@js-joda/timezone": "^2.21.2"
3332
},
3433
"devDependencies": {
3534
"@types/jest": "^29.5.14",

src/rules/operation-builder.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
const parseDuration = require('parse-duration');
1+
const time = require('@js-joda/core'); // standard JS-Joda is enough as we only parse durations
22
const items = require('../items/items');
33

44
/**
55
* @typedef { import("../items/items").Item } Item
66
* @private
77
*/
8-
/**
9-
* @typedef {import('@js-joda/core').ZonedDateTime} time.ZonedDateTime
10-
* @private
11-
*/
128
/**
139
* @typedef {import('../quantity').Quantity} Quantity
1410
* @private
@@ -447,7 +443,7 @@ class TimingItemStateOperation extends OperationConfig {
447443
/** @private */
448444
this.item_changed_trigger_config = itemChangedTriggerConfig;
449445
/** @private */
450-
this.duration_ms = (typeof duration === 'number' ? duration : parseDuration.parse(duration));
446+
this.duration_ms = (typeof duration === 'number' ? duration : time.Duration.parse(duration).toMillis());
451447

452448
/** @private */
453449
this._complete = itemChangedTriggerConfig._complete;

types/rules/operation-builder.d.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export type Item = {
99
readonly numericState: number;
1010
readonly quantityState: import("../quantity").Quantity;
1111
readonly rawState: HostState;
12+
/**
13+
* Specify the rule group for this rule
14+
*
15+
* @param {string} group the group this rule belongs to.
16+
* @returns {OperationBuilder} this
17+
*/
1218
readonly members: any[];
1319
readonly descendents: any[];
1420
readonly isUninitialized: boolean;
@@ -205,10 +211,6 @@ export class CopyStateOperation extends OperationConfig {
205211
* @typedef { import("../items/items").Item } Item
206212
* @private
207213
*/
208-
/**
209-
* @typedef {import('@js-joda/core').ZonedDateTime} time.ZonedDateTime
210-
* @private
211-
*/
212214
/**
213215
* @typedef {import('../quantity').Quantity} Quantity
214216
* @private
@@ -333,8 +335,6 @@ declare class OperationConfig {
333335
*/
334336
build(name?: string, description?: string, tags?: Array<string>, id?: string): void;
335337
}
336-
declare namespace time {
337-
type ZonedDateTime = import('@js-joda/core').ZonedDateTime;
338-
}
338+
import time = require("@js-joda/core");
339339
export {};
340340
//# sourceMappingURL=operation-builder.d.ts.map

types/rules/operation-builder.d.ts.map

+1-1
Original file line numberDiff line numberDiff line change

0 commit comments

Comments
 (0)