-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
578 lines (530 loc) · 22.5 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
"use strict";
/*
* Created with @iobroker/create-adapter v2.1.1
*/
// The adapter-core module gives you access to the core ioBroker functions
// you need to create an adapter
const utils = require("@iobroker/adapter-core");
const schedule = require("node-schedule");
// Load your modules here, e.g.:
// const fs = require("fs");
class OperatingHours extends utils.Adapter {
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
constructor(options) {
super({
...options,
name: "operating-hours",
});
this.on("ready", this.onReady.bind(this));
this.on("stateChange", this.onStateChange.bind(this));
// this.on("objectChange", this.onObjectChange.bind(this));
this.on("message", this.onMessage.bind(this));
this.on("unload", this.onUnload.bind(this));
this.AdapterObjectsAtStart = {};
this.configedChannels = {};
this.internalIds = {
state: "state",
resetCronJob: "resetCronJob",
timestamp : "timestamp"
};
this.channelFolders = {
operatingHours : "operatingHours",
administrative : "administrative"
};
this.operatingHours = {
milliseconds : {name:"milliseconds",type:"number",write:true,unit:"ms",def:0},
seconds : {name:"seconds",type:"number",write:true,unit:"s",def:0},
minutes : {name:"minutes",type:"number",write:true,unit:"min",def:0},
hours : {name:"hours",type:"number",write:true,unit:"h",def:0},
days : {name:"days",type:"number",write:true,unit:"d",def:0},
timestring_h_m :{name:"timestring_h_m",type:"string",write:false,unit:"h:m",def:""},
timestring_h_m_s :{name:"timestring_h_m_s",type:"string",write:false,unit:"h:m:s",def:""},
timestring_d_h_m_s :{name:"timestring_d_h_m_s",type:"string",write:false,unit:"d:h:m:s",def:""},
json :{name:"json",type:"string",write:false,unit:"",def:""},
averageOnTime_h_m_s :{name:"averageOnTime_h_m_s",type:"string",write:false,unit:"h:m:s",def:""},
};
this.administrative = {
enableCounting : {name:"enableCounting", type:"boolean", write:true, def:false},
activationCounter : {name:"activationCounter", type:"number", write:false, def:0}
};
this.timeouts = {};
this.timeoutIds = {
countingTimeout : "countingTimeout"
};
this.cronJobs ={};
this.jobId = "jobId";
}
// Clear all Timeouts, if there are some
clearAllTimeouts(){
for(const myTimeout in this.timeouts)
{
this.clearTimeout(this.timeouts[myTimeout]);
delete this.timeouts[myTimeout];
}
}
/**
* Is called when databases are connected and adapter received configuration.
*/
async onReady() {
// Generating the configed id internal (cleared)
for(const element of this.config.statesTable){
if(!this.configedChannels[this.getChannelId(element[this.internalIds.state])]){
this.configedChannels[this.getChannelId(element[this.internalIds.state])] = {};
this.configedChannels[this.getChannelId(element[this.internalIds.state])].name = element[this.internalIds.state];
this.configedChannels[this.getChannelId(element[this.internalIds.state])].resetCronJob = element[this.internalIds.resetCronJob];
}
else{
this.log.warn(`The id for "${element[this.internalIds.state]}" cound not be created. It is the same as "${this.configedChannels[this.getChannelId(element[this.internalIds.state])].name}".`);
}
}
// delete not configutred states
this.delNotConfiguredStates();
// Create configured states if not created
await this.createInternalStates();
// Subscribe all internal states
this.subscribeStates("*");
// countup the enabled channels
this.counting();
// create cronJobs
this.createCronJbs();
}
// deletes not configured states
async delNotConfiguredStates()
{
// Get all objects in the adapter (later)
this.AdapterObjectsAtStart = await this.getAdapterObjectsAsync();
let activeString = "";
for(const channel in this.configedChannels){
// Operating hours löschen
for(const state in this.operatingHours){
activeString = `${this.namespace}.${channel}.${this.channelFolders.operatingHours}.${state}`;
delete this.AdapterObjectsAtStart[activeString];
}
activeString = `${this.namespace}.${channel}.${this.channelFolders.operatingHours}`;
delete this.AdapterObjectsAtStart[activeString];
// Administrative löschen
for(const state in this.administrative){
activeString = `${this.namespace}.${channel}.${this.channelFolders.administrative}.${state}`;
delete this.AdapterObjectsAtStart[activeString];
}
activeString = `${this.namespace}.${channel}.${this.channelFolders.administrative}`;
delete this.AdapterObjectsAtStart[activeString];
// Channel löschen
activeString = `${this.namespace}.${channel}`;
delete this.AdapterObjectsAtStart[activeString];
}
// delete the remaining states
for(const state in this.AdapterObjectsAtStart){
this.delObjectAsync(state);
}
}
// creates internal states
async createInternalStates(){
for(const channel in this.configedChannels){
// create channel
await this.setObjectNotExistsAsync(`${channel}`,{
type:"channel",
common:{
name: this.configedChannels[channel].name
},
native : {},
});
if(!this.configedChannels[channel][this.internalIds.timestamp]){
this.configedChannels[channel][this.internalIds.timestamp] = {};
}
this.configedChannels[channel].timestamp = Date.now();
// create operating hours folder
await this.setObjectNotExistsAsync(`${channel}.${this.channelFolders.operatingHours}`,{
type:"folder",
common:{
name: this.channelFolders.operatingHours
},
native : {},
});
if(!this.configedChannels[channel][this.channelFolders.operatingHours]){
this.configedChannels[channel][this.channelFolders.operatingHours] ={};
}
// Create operating hour states
for(const operatinghour of Object.values(this.operatingHours)){
await this.setObjectNotExistsAsync(`${channel}.${this.channelFolders.operatingHours}.${operatinghour.name}`,{
type: "state",
common: {
name: operatinghour.name,
type: operatinghour.type,
role: "value",
read: true,
write: operatinghour.write,
unit: operatinghour.unit,
def:operatinghour.def
},
native: {},
});
if(!this.configedChannels[channel][this.channelFolders.operatingHours][operatinghour.name]){
this.configedChannels[channel][this.channelFolders.operatingHours][operatinghour.name] ={};
}
const state = await this.getStateAsync(`${channel}.${this.channelFolders.operatingHours}.${operatinghour.name}`);
if(state){
this.configedChannels[channel][this.channelFolders.operatingHours][operatinghour.name] = state.val;
}
else{
this.configedChannels[channel][this.channelFolders.operatingHours][operatinghour.name] = 0;
}
}
// create administrative folder
await this.setObjectNotExistsAsync(`${channel}.${this.channelFolders.administrative}`,{
type:"folder",
common:{
name: this.channelFolders.administrative
},
native : {},
});
if(!this.configedChannels[channel][this.channelFolders.administrative]){
this.configedChannels[channel][this.channelFolders.administrative] ={};
}
// Create administrative states
for( const administrative of Object.values(this.administrative)){
await this.setObjectNotExistsAsync(`${channel}.${this.channelFolders.administrative}.${administrative.name}`,{
type: "state",
common: {
name: administrative.name,
type: administrative.type,
role: "value",
read: true,
write: administrative.write,
def: administrative.def
},
native: {},
});
if(!this.configedChannels[channel][this.channelFolders.administrative][administrative.name]){
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] ={};
}
const state = await this.getStateAsync(`${channel}.${this.channelFolders.administrative}.${administrative.name}`);
if(state){
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] = state.val;
}
else{
this.configedChannels[channel][this.channelFolders.administrative][administrative.name] = administrative.def;
}
}
}
}
// Count the operatinghours
counting(){
let countingEnabled = false;
const timestamp = Date.now();
if(this.timeouts.countingTimeout){
this.clearTimeout(this.timeouts.countingTimeout);
delete this.timeouts.countingTimeout;
}
for(const channel in this.configedChannels){
const channelObj = this.configedChannels[channel];
if(channelObj.administrative.enableCounting){
// Aktivierung des späteren timeout aufrufes
countingEnabled = true;
this.setOperatingHours(channel, channelObj.operatingHours.milliseconds + (timestamp - channelObj.timestamp), timestamp);
}
}
if(countingEnabled){
this.timeouts.countingTimeout = setTimeout(this.counting.bind(this),this.config.refreshRate);
}
}
// Get the channel id in caseof the text implements not allowed characters
getChannelId(configedId){
return (configedId || "").replace(this.FORBIDDEN_CHARS, "_").replace(/[-\s]|\.$/g, "_");
}
// Set operatinghours (all formats in case of the milliseconds)
setOperatingHours(channel,milliseconds,ts){
// Rohdaten erzeugen
const rawdata = this.generateRawdata(milliseconds);
// Berechenn der Werte
// const seconds = milliseconds/1000;
// const minutes = milliseconds/60000;
// const hours = milliseconds/3600000;
// const days = milliseconds/86400000;
// Erzeugen der Strings mit Stunden
const hourlength = Math.trunc(rawdata.hours).toString().length;
let hourindex = 2;
if(hourlength > 2){
hourindex = hourlength;
}
const h_m = ("0" + Math.trunc(rawdata.hours).toString()).slice(-hourindex) + ":" + ("0" + Math.trunc((rawdata.minutes%60)).toString()).slice(-2);
const h_m_s = h_m + ":" + ("0" + Math.trunc((rawdata.seconds%60)).toString()).slice(-2);
// Erzeugen des String mit Tagen
const hourlengthWithDays = Math.trunc(rawdata.hours%24).toString().length;
let hourindexWithDays = 2;
if(hourlengthWithDays > 2){
hourindexWithDays = hourlengthWithDays;
}
const h_mWithDays = ("0" + Math.trunc(rawdata.hours%24).toString()).slice(-hourindexWithDays) + ":" + ("0" + Math.trunc((rawdata.minutes%60)).toString()).slice(-2);
const h_m_sWithDays = h_mWithDays + ":" + ("00" + Math.trunc((rawdata.seconds%60)).toString()).slice(-2);
const daylength = Math.trunc(rawdata.days).toString().length;
let dayindex = 2;
if(daylength > 2){
dayindex = daylength;
}
const d_h_m_s = ("0" + Math.trunc(rawdata.days).toString()).slice(-dayindex) + ":" + h_m_sWithDays;
// Erzeugen des Json Objekts für den JSON-String
const json = this.dissoveRawdata(rawdata);
// Berechnen der mittleren Einschaltzeit
const averageOnTimeSeconds = rawdata.seconds / this.configedChannels[channel].administrative.activationCounter;
const averageOnTimeMinutes = rawdata.minutes / this.configedChannels[channel].administrative.activationCounter;
const averageOnTimeHours = rawdata.hours / this.configedChannels[channel].administrative.activationCounter;
// Erzeugen der Strings mit Stunden
const averagehourlength = Math.trunc(averageOnTimeHours).toString().length;
let averagehourstring = "00";
let averagehourindex = 2;
for(averagehourindex; averagehourindex < averagehourlength; averagehourindex++){
averagehourstring += "0";
}
const averageOnTime_h_m_s = (averagehourstring + Math.trunc(averageOnTimeHours).toString()).slice(-averagehourindex) + ":" + ("00" + Math.trunc((averageOnTimeMinutes%60)).toString()).slice(-2) + ":" + ("00" + Math.trunc((averageOnTimeSeconds%60)).toString()).slice(-2);
// Schreiben der states
this.configedChannels[channel].timestamp = ts;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.milliseconds.name}`, rawdata.milliseconds,true);
this.configedChannels[channel].operatingHours.milliseconds = milliseconds;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.seconds.name}`, rawdata.seconds,true);
this.configedChannels[channel].operatingHours.seconds = rawdata.seconds;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.minutes.name}`, rawdata.minutes,true);
this.configedChannels[channel].operatingHours.minutes = rawdata.minutes;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.hours.name}`, rawdata.hours,true);
this.configedChannels[channel].operatingHours.hours = rawdata.hours;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.days.name}`, rawdata.days,true);
this.configedChannels[channel].operatingHours.days = rawdata.days;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.timestring_h_m.name}`,h_m,true);
this.configedChannels[channel].operatingHours.timestring_h_m = h_m;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.timestring_h_m_s.name}`,h_m_s,true);
this.configedChannels[channel].operatingHours.timestring_h_m_s = h_m_s;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.timestring_d_h_m_s.name}`,d_h_m_s,true);
this.configedChannels[channel].operatingHours.timestring_d_h_m_s = d_h_m_s;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.json.name}`,JSON.stringify(json),true);
this.configedChannels[channel].operatingHours.json = json;
this.setState(`${channel}.${this.channelFolders.operatingHours}.${this.operatingHours.averageOnTime_h_m_s.name}`,averageOnTime_h_m_s,true);
this.configedChannels[channel].operatingHours.averageOnTime_h_m_s = averageOnTime_h_m_s;
// Rücksetzen des counters, wenn die millesekunden 0 sind
if(milliseconds === 0){
if(this.configedChannels[channel].administrative.enableCounting){
this.configedChannels[channel].administrative.activationCounter = 1;
}
else{
this.configedChannels[channel].administrative.activationCounter =0;
}
this.setState(`${channel}.${this.channelFolders.administrative}.${this.administrative.activationCounter.name}`,this.configedChannels[channel].administrative.activationCounter ,true);
}
}
createCronJbs(){
for(const channel in this.configedChannels){
if( this.configedChannels[channel].resetCronJob !== null &&
this.configedChannels[channel].resetCronJob !== ""){
if(!this.cronJobs[this.configedChannels[channel].resetCronJob]){
this.cronJobs[this.configedChannels[channel].resetCronJob] = {};
this.cronJobs[this.configedChannels[channel].resetCronJob][this.jobId] = schedule.scheduleJob(this.configedChannels[channel].resetCronJob,this.resetWithCronJob.bind(this,this.configedChannels[channel].resetCronJob));
if(this.cronJobs[this.configedChannels[channel].resetCronJob][this.jobId]){
this.log.debug(`cronjob ${this.configedChannels[channel].resetCronJob} was created.`);
}
else{
this.log.warn(`reset cronjob ${this.configedChannels[channel].resetCronJob} for the state ${channel} can not be created.`);
}
}
this.cronJobs[this.configedChannels[channel].resetCronJob][channel] = {};
}
}
}
resetWithCronJob(cronJob){
const timestamp = Date.now();
for(const ele in this.cronJobs[cronJob]){
if(ele != this.jobId){
this.setOperatingHours(ele, 0, timestamp);
}
}
}
/**
* Is called when adapter shuts down - callback has to be called under any circumstances!
* @param {() => void} callback
*/
onUnload(callback) {
try {
// clear all schedules
for(const cronJob in this.cronJobs)
{
schedule.cancelJob(this.cronJobs[cronJob][this.jobId]);
}
this.clearAllTimeouts();
callback();
} catch (e) {
callback();
}
}
/**
* Is called if a subscribed state changes
* @param {string} id
* @param {ioBroker.State | null | undefined} state
*/
onStateChange(id, state) {
if (state) {
// Es werden nur Werte beachtet, welche mit ack = false geschrieben wurden.
if(!state.ack){
let newId = id.substring(this.namespace.length,id.length);
// Vorletzten punkt heraus finden
let beforeLastIndex = this.namespace.length;
while(newId.indexOf(".") !== newId.lastIndexOf(".")){
beforeLastIndex += newId.indexOf(".") + 1;
newId = id.substring(beforeLastIndex,id.length);
}
// Endung der id und den channel herausfiltern
const idExtention = id.substring(beforeLastIndex,id.length);
const channel = id.substring(this.namespace.length + 1,beforeLastIndex - 1); // -1, wegen dem letzten Punkt für die foldertrennung
// Prüfen, ob das enableCounting geändert wurde
if(idExtention.indexOf(this.administrative.enableCounting.name) !== -1){
// Zuweisen des neuen States
const lastState = this.configedChannels[channel][this.channelFolders.administrative].enableCounting;
this.configedChannels[channel][this.channelFolders.administrative].enableCounting = state.val;
this.setState(`${channel}.${this.channelFolders.administrative}.${this.administrative.enableCounting.name}`,state.val,true);
// Abfrage, ob sich der Wert geändert hat (Nur dann, wir etwas unternommen)
if(state.val !== lastState){
// Abfrage, ob der neue Wert true ist
if(state.val){
// Hochzählen des aktivierungscounters
this.configedChannels[channel].administrative.activationCounter += 1;
this.setState(`${channel}.${this.channelFolders.administrative}.${this.administrative.activationCounter.name}`,this.configedChannels[channel].administrative.activationCounter,true);
this.configedChannels[channel].timestamp = state.ts;
if(!this.timeouts.countingTimeout){
this.timeouts.countingTimeout = setTimeout(this.counting.bind(this),this.config.refreshRate);
}
}
else{
if(this.timeouts.countingTimeout){
this.clearTimeout(this.timeouts.countingTimeout);
delete this.timeouts.countingTimeout;
}
this.counting();
this.setOperatingHours(channel, this.configedChannels[channel].operatingHours.milliseconds + (state.ts - this.configedChannels[channel].timestamp), state.ts);
}
}
}
// Prüfen, ob sich ein Betriebsstundenzähler geändert hat
else if(idExtention.indexOf(this.channelFolders.operatingHours) !== -1){
// Nun wird noch geprüft,welcher Betriebsstundenwert geändert wurde => Somitkann dieser in ms umgerechnet werden.
let milliseconds = 0;
if(typeof(state.val) === "number"){ // auf den Type number prüfen
if(newId.indexOf(this.operatingHours.milliseconds.name) !== -1){
milliseconds = state.val;
}
else if(newId.indexOf(this.operatingHours.seconds.name) !== -1){
if(state.val !== null){
milliseconds = state.val * 1000;
}
}
else if(newId.indexOf(this.operatingHours.minutes.name) !== -1){
if(state.val !== null){
milliseconds = state.val * 60000;
}
}
else if(newId.indexOf(this.operatingHours.hours.name) !== -1){
if(state.val !== null){
milliseconds = state.val * 3600000;
}
}
else if(newId.indexOf(this.operatingHours.days.name) !== -1){
if(state.val !== null){
milliseconds = state.val * 86400000;
}
}
this.setOperatingHours(channel,milliseconds,state.ts);
}
}
}
} else {
// The state was deleted
this.log.info(`state ${id} deleted`);
}
}
// If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor.
// /**
// * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ...
// * Using this method requires "common.messagebox" property to be set to true in io-package.json
// * @param {ioBroker.Message} obj
// */
onMessage(obj) {
if (typeof obj === "object" && obj.message) {
if(obj.command === "getOperatingHours"){
if(this.configedChannels[obj.message.name]){
// First get the "old" state-data (actual in state)
const oldRawdata = this.generateRawdata(this.configedChannels[obj.message.name].operatingHours.milliseconds);
const oldDissolved = this.dissoveRawdata(oldRawdata);
const oldState = {rawdata: oldRawdata, dissolved: oldDissolved};
let timestamp = Date.now();
// If counting is disabled, dont add the time from the last timestamp till now
if(!this.configedChannels[obj.message.name].administrative.enableCounting){
timestamp = this.configedChannels[obj.message.name].timestamp;
}
const milliseconds = this.configedChannels[obj.message.name].operatingHours.milliseconds + (timestamp - this.configedChannels[obj.message.name].timestamp);
const rawdata = this.generateRawdata(milliseconds);
const dissolved = this.dissoveRawdata(rawdata);
const state = {rawdata: rawdata, dissolved: dissolved};
const data = {info: "operatinghours successfully transmitted", state: state, oldState: oldState};
this.sendTo(obj.from, obj.command, data, obj.callback);
}
else{
if(obj.callback){
const data = {info: `no valid statename received: ${obj.message.name}`};
this.sendTo(obj.from, obj.command, data, obj.callback);
}
}
}
else{
if(obj.callback){
const data = {error: `no valid command received: ${obj.command}`};
this.sendTo(obj.from, obj.command, data, obj.callback);
}
}
}
}
generateRawdata(milliseconds){
return {milliseconds: milliseconds, seconds: milliseconds/1000, minutes: milliseconds/60000, hours: milliseconds/3600000, days: milliseconds/86400000};
}
dissoveRawdata(rawdata){
const dissolved = {};
let internalMillisecons = rawdata.milliseconds;
if(Math.trunc(rawdata.days) > 0){
internalMillisecons -= Math.trunc(rawdata.days) * 86400000;
dissolved.days = Math.trunc(rawdata.days);
}
else{
dissolved.days = 0;
}
if(Math.trunc(rawdata.hours%24) > 0){
internalMillisecons -= Math.trunc(rawdata.hours%24) * 3600000;
dissolved.hours = Math.trunc(rawdata.hours%24);
}
else{
dissolved.hours = 0;
}
if(Math.trunc(rawdata.minutes%60) > 0){
internalMillisecons -= Math.trunc(rawdata.minutes%60) * 60000;
dissolved.minutes = Math.trunc(rawdata.minutes%60);
}
else{
dissolved.minutes = 0;
}
if(Math.trunc(rawdata.seconds%60) > 0){
internalMillisecons -= Math.trunc(rawdata.seconds%60) * 1000;
dissolved.seconds = Math.trunc(rawdata.seconds%60);
}
else{
dissolved.seconds = 0;
}
dissolved.milliseconds = internalMillisecons;
return dissolved;
}
}
if (require.main !== module) {
// Export the constructor in compact mode
/**
* @param {Partial<utils.AdapterOptions>} [options={}]
*/
module.exports = (options) => new OperatingHours(options);
} else {
// otherwise start the instance directly
new OperatingHours();
}