iobroker.javascript 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +9 -8
  2. package/admin/asset-manifest.json +11 -11
  3. package/admin/google-blockly/own/blocks_convert.js +4 -4
  4. package/admin/google-blockly/own/blocks_system.js +55 -13
  5. package/admin/google-blockly/own/blocks_time.js +1 -1
  6. package/admin/google-blockly/own/blocks_trigger.js +2 -2
  7. package/admin/google-blockly/own/blocks_words.js +9 -0
  8. package/admin/static/js/376.215ba3ed.chunk.js +9 -0
  9. package/admin/static/js/376.215ba3ed.chunk.js.map +1 -0
  10. package/admin/static/js/402.cf6fe7b7.chunk.js +198 -0
  11. package/admin/static/js/402.cf6fe7b7.chunk.js.map +1 -0
  12. package/admin/static/js/62.e8512a43.chunk.js +187 -0
  13. package/admin/static/js/62.e8512a43.chunk.js.map +1 -0
  14. package/admin/static/js/{848.77a7611f.chunk.js → 848.3c1a4d2e.chunk.js} +46 -46
  15. package/admin/static/js/848.3c1a4d2e.chunk.js.map +1 -0
  16. package/admin/static/js/main.2bd6b291.js +6 -0
  17. package/admin/static/js/main.2bd6b291.js.map +1 -0
  18. package/admin/tab.html +1 -1
  19. package/docs/de/usage.md +1 -1
  20. package/docs/en/blockly.md +3 -3
  21. package/docs/en/javascript.md +28 -3
  22. package/io-package.json +64 -13
  23. package/lib/sandbox.js +225 -83
  24. package/main.js +75 -15
  25. package/package.json +1 -1
  26. package/admin/static/js/402.2b754320.chunk.js +0 -198
  27. package/admin/static/js/402.2b754320.chunk.js.map +0 -1
  28. package/admin/static/js/55.2fbb4209.chunk.js +0 -9
  29. package/admin/static/js/55.2fbb4209.chunk.js.map +0 -1
  30. package/admin/static/js/62.97617f7b.chunk.js +0 -185
  31. package/admin/static/js/62.97617f7b.chunk.js.map +0 -1
  32. package/admin/static/js/848.77a7611f.chunk.js.map +0 -1
  33. package/admin/static/js/main.444faaef.js +0 -6
  34. package/admin/static/js/main.444faaef.js.map +0 -1
package/lib/sandbox.js CHANGED
@@ -283,7 +283,7 @@ function sandBox(script, name, verbose, debug, context) {
283
283
  * @returns {Promise<void>}
284
284
  */
285
285
  async function ensureObjectStructure(id) {
286
- //adapter.log.debug(`ensure Logic called for "${id}": ${verifiedObjects[id]}`);
286
+ // adapter.log.debug(`ensure Logic called for "${id}": ${verifiedObjects[id]}`);
287
287
  if (!validIdForAutomaticFolderCreation(id)) {
288
288
  return;
289
289
  }
@@ -300,7 +300,7 @@ function sandBox(script, name, verbose, debug, context) {
300
300
 
301
301
  context.folderCreationVerifiedObjects[id] = true;
302
302
  for (const part of idArr) {
303
- idToCheck += '.' + part;
303
+ idToCheck += `.${part}`;
304
304
  //adapter.log.debug(` check "${idToCheck}": ${verifiedObjects[idToCheck]}`);
305
305
  if (context.folderCreationVerifiedObjects[idToCheck] === true || objects[idToCheck]) {
306
306
  continue;
@@ -318,11 +318,11 @@ function sandBox(script, name, verbose, debug, context) {
318
318
  await adapter.setForeignObjectAsync(idToCheck, {
319
319
  type: 'folder',
320
320
  common: {
321
- name: part
321
+ name: part,
322
322
  },
323
323
  native: {
324
- autocreated: 'by automatic ensure logic'
325
- }
324
+ autocreated: 'by automatic ensure logic',
325
+ },
326
326
  });
327
327
  } catch (err) {
328
328
  adapter.log.info(`Could not automatically create folder object ${idToCheck}: ${err.message}`);
@@ -416,7 +416,7 @@ function sandBox(script, name, verbose, debug, context) {
416
416
  try {
417
417
  callback.call(sandbox, `Could not stringify value for type ${actualCommonType} and id ${id}: ${err.message}`);
418
418
  } catch (e) {
419
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
419
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
420
420
  }
421
421
  }
422
422
  }
@@ -469,7 +469,7 @@ function sandBox(script, name, verbose, debug, context) {
469
469
  context.interimStateValues[id] = state;
470
470
  }
471
471
  setStateFunc(id, state, err => {
472
- err && sandbox.log('setForeignState: ' + err, 'error');
472
+ err && sandbox.log(`setForeignState: ${err}`, 'error');
473
473
  // If adapter holds all states
474
474
  if (err && !adapter.config.subscribe) {
475
475
  delete context.interimStateValues[id];
@@ -480,7 +480,7 @@ function sandBox(script, name, verbose, debug, context) {
480
480
  try {
481
481
  callback.call(sandbox);
482
482
  } catch (e) {
483
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
483
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
484
484
  }
485
485
  });
486
486
  }
@@ -493,7 +493,7 @@ function sandBox(script, name, verbose, debug, context) {
493
493
  try {
494
494
  callback.call(sandbox, `State "${id}" not found`);
495
495
  } catch (e) {
496
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
496
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
497
497
  }
498
498
  });
499
499
  }
@@ -1027,6 +1027,7 @@ function sandBox(script, name, verbose, debug, context) {
1027
1027
  return this;
1028
1028
  };
1029
1029
  result.setBinaryState = function (state, isAck, callback) {
1030
+ sandbox.log(`$.setBinaryState(id=${this[0]}) is deprecated. Please use Files instead!`, 'info');
1030
1031
  if (typeof isAck === 'function') {
1031
1032
  callback = isAck;
1032
1033
  isAck = undefined;
@@ -1037,6 +1038,7 @@ function sandBox(script, name, verbose, debug, context) {
1037
1038
  return this;
1038
1039
  };
1039
1040
  result.setBinaryStateAsync = async function (state, isAck) {
1041
+ sandbox.log(`$.setBinaryStateAsync(id=${this[0]}) is deprecated. Please use Files instead!`, 'info');
1040
1042
  if (isAck === true || isAck === false || isAck === 'true' || isAck === 'false') {
1041
1043
  if (isObject(state)) {
1042
1044
  state.ack = isAck;
@@ -1935,17 +1937,17 @@ function sandBox(script, name, verbose, debug, context) {
1935
1937
  return context.convertBackStringifiedValues(id, context.interimStateValues[id]);
1936
1938
  }
1937
1939
  return context.convertBackStringifiedValues(id, states[id]);
1938
- } else if (states[adapter.namespace + '.' + id]) {
1939
- sandbox.verbose && sandbox.log(`getState(id=${id}, timerId=${timers[id]}) => ${states[adapter.namespace + '.' + id]}`, 'info');
1940
- if (context.interimStateValues[adapter.namespace + '.' + id] !== undefined) {
1941
- return context.convertBackStringifiedValues(id, context.interimStateValues[adapter.namespace + '.' + id]);
1940
+ } else if (states[`${adapter.namespace}.${id}`]) {
1941
+ sandbox.verbose && sandbox.log(`getState(id=${id}, timerId=${timers[id]}) => ${states[`${adapter.namespace}.${id}`]}`, 'info');
1942
+ if (context.interimStateValues[`${adapter.namespace}.${id}`] !== undefined) {
1943
+ return context.convertBackStringifiedValues(id, context.interimStateValues[`${adapter.namespace}.${id}`]);
1942
1944
  }
1943
- return context.convertBackStringifiedValues(id, states[adapter.namespace + '.' + id]);
1945
+ return context.convertBackStringifiedValues(id, states[`${adapter.namespace}.${id}`]);
1944
1946
  }
1945
1947
 
1946
1948
  sandbox.verbose && sandbox.log(`getState(id=${id}, timerId=${timers[id]}) => not found`, 'info');
1947
1949
 
1948
- context.logWithLineInfo && context.logWithLineInfo.warn(`getState "${id}" not found (3)${states[id] !== undefined ? ' states[id]=' + states[id] : ''}`); ///xxx
1950
+ context.logWithLineInfo && context.logWithLineInfo.warn(`getState "${id}" not found (3)${states[id] !== undefined ? ` states[id]=${states[id]}` : ''}`); ///xxx
1949
1951
  return {val: null, notExist: true};
1950
1952
  }
1951
1953
  }
@@ -1964,8 +1966,15 @@ function sandBox(script, name, verbose, debug, context) {
1964
1966
  },
1965
1967
  existsState: function (id, callback) {
1966
1968
  if (typeof callback === 'function') {
1967
- adapter.getForeignObject(id, (err, obj) =>
1968
- callback(err, obj && obj.type === 'state' && !!states[id]));
1969
+ adapter.getForeignObject(id, (err, obj) => {
1970
+ if (adapter.config.subscribe) {
1971
+ adapter.getForeignState(id, (err, state) => {
1972
+ callback(err, obj && obj.type === 'state' && !!state);
1973
+ });
1974
+ } else {
1975
+ callback(err, obj && obj.type === 'state' && !!states[id]);
1976
+ }
1977
+ });
1969
1978
  } else {
1970
1979
  return !!states[id];
1971
1980
  }
@@ -2144,7 +2153,7 @@ function sandBox(script, name, verbose, debug, context) {
2144
2153
  }
2145
2154
 
2146
2155
  if (!name.startsWith('alias.0.')) {
2147
- name = 'alias.0.' + name;
2156
+ name = `alias.0.${name}`;
2148
2157
  }
2149
2158
 
2150
2159
  common = common || {};
@@ -2231,7 +2240,7 @@ function sandBox(script, name, verbose, debug, context) {
2231
2240
 
2232
2241
  return sandbox.createState(name, undefined, forceCreation, common, native, callback);
2233
2242
  },
2234
- createState: function (name, initValue, forceCreation, common, native, callback) {
2243
+ createState: async function (name, initValue, forceCreation, common, native, callback) {
2235
2244
  if (typeof native === 'function') {
2236
2245
  callback = native;
2237
2246
  native = {};
@@ -2358,7 +2367,7 @@ function sandBox(script, name, verbose, debug, context) {
2358
2367
  try {
2359
2368
  callback.call(sandbox, err);
2360
2369
  } catch (e) {
2361
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2370
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
2362
2371
  }
2363
2372
  }
2364
2373
  return;
@@ -2382,7 +2391,7 @@ function sandBox(script, name, verbose, debug, context) {
2382
2391
 
2383
2392
  sandbox.verbose && sandbox.log(`createState(name=${name}, initValue=${initValue}, forceCreation=${forceCreation}, common=${JSON.stringify(common)}, native=${JSON.stringify(native)}, isAlias=${isAlias})`, 'debug');
2384
2393
 
2385
- let id = adapter.namespace + '.' + name;
2394
+ let id = `${adapter.namespace}.${name}`;
2386
2395
  if (name.match(/^javascript\.\d+\./) || name.startsWith('0_userdata.0.') || isAlias) {
2387
2396
  id = name;
2388
2397
  }
@@ -2391,79 +2400,212 @@ function sandBox(script, name, verbose, debug, context) {
2391
2400
  } else if (id.match(/^javascript\.\d+\.scriptProblem/)) {
2392
2401
  sandbox.log(`Own states (${id}) should not be created in javascript.X.scriptProblem.*! Please move the states to 0_userdata.0.*`, 'info');
2393
2402
  }
2394
- adapter.getForeignObject(id, async (err, obj) => {
2395
- if (obj && obj._id && validIdForAutomaticFolderCreation(obj._id) && obj.type === 'folder' && obj.native && obj.native.autocreated === 'by automatic ensure logic') {
2396
- // ignore default created object because we now have a more defined one
2397
- obj = null;
2403
+
2404
+ // User can create aliases by two ways:
2405
+ // - id is starting with "alias.0." and common.alias.id is set, so the state defined in common.alias.id will be created automatically if not exists
2406
+ // - id is not starting with "alias.0.", but common.alias is set, so the state defined in common.alias will be created automatically if not exists
2407
+ if (!isAlias && common.alias) {
2408
+ // check and create if not exists the alias
2409
+ let alias = common.alias;
2410
+ delete common.alias;
2411
+ if (typeof alias === 'string') {
2412
+ alias = {
2413
+ id: alias,
2414
+ };
2415
+ } else if (typeof alias === 'boolean') {
2416
+ const parts = id.split('.');
2417
+ parts[0] = 'alias';
2418
+ parts[1] = '0';
2419
+
2420
+ alias = {
2421
+ id: parts.join('.'),
2422
+ };
2423
+ }
2424
+
2425
+ if (!alias.id.startsWith('alias.0.')) {
2426
+ alias.id = `alias.0.${alias.id}`;
2398
2427
  }
2399
2428
 
2400
- if (err || !obj || forceCreation) {
2401
- // create new one
2402
- const newObj = {
2403
- common,
2404
- native,
2405
- type: 'state'
2429
+ let aObj;
2430
+ try {
2431
+ aObj = await adapter.getForeignObjectAsync(alias.id);
2432
+ } catch (e) {
2433
+ // ignore
2434
+ }
2435
+ if (!aObj) {
2436
+ try {
2437
+ await adapter.setForeignObjectAsync(alias.id, {
2438
+ type: 'state',
2439
+ common: {
2440
+ name: `Alias to ${id}`,
2441
+ role: 'state',
2442
+ type: common.type,
2443
+ read: common.read,
2444
+ write: common.write,
2445
+ unit: common.unit,
2446
+ alias: {
2447
+ id,
2448
+ read: alias.read,
2449
+ write: alias.write,
2450
+ },
2451
+ },
2452
+ native: {},
2453
+ });
2454
+ } catch (e) {
2455
+ adapter.log.error(`Cannot create alias "${alias.id}": ${e}`);
2456
+ }
2457
+ }
2458
+ } else if (isAlias && common.alias) {
2459
+ if (typeof common.alias === 'string') {
2460
+ common.alias = {
2461
+ id: common.alias,
2406
2462
  };
2407
- adapter.setForeignObject(id, newObj, async (err) => {
2408
- if (err) {
2409
- adapter.log.warn(`Cannot set object "${id}": ${err}`);
2410
- if (typeof callback === 'function') {
2411
- try {
2412
- callback.call(sandbox, err);
2413
- } catch (e) {
2414
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2415
- }
2416
- }
2417
- return;
2463
+ }
2464
+ const readId = typeof common.alias.id === 'string' ? common.alias.id : common.alias.id.read;
2465
+ let writeId = typeof common.alias.id === 'string' ? common.alias.id : common.alias.id.write;
2466
+ if (writeId === readId) {
2467
+ writeId = undefined;
2468
+ }
2469
+ // try to create the linked states
2470
+ let aObj;
2471
+ try {
2472
+ aObj = await adapter.getForeignObjectAsync(readId);
2473
+ } catch (e) {
2474
+ // ignore
2475
+ }
2476
+ if (!aObj) {
2477
+ try {
2478
+ await adapter.setForeignObjectAsync(readId, {
2479
+ type: 'state',
2480
+ common: {
2481
+ name: `State for ${id}`,
2482
+ role: 'state',
2483
+ type: common.type,
2484
+ read: common.read,
2485
+ write: common.write,
2486
+ unit: common.unit,
2487
+ },
2488
+ native: {},
2489
+ });
2490
+ } catch (e) {
2491
+ adapter.log.error(`Cannot create alias "${readId}": ${e}`);
2492
+ }
2493
+ }
2494
+ if (writeId && common.write !== false) {
2495
+ try {
2496
+ aObj = await adapter.getForeignObjectAsync(writeId);
2497
+ } catch (e) {
2498
+ // ignore
2499
+ }
2500
+ if (!aObj) {
2501
+ try {
2502
+ await adapter.setForeignObjectAsync(writeId, {
2503
+ type: 'state',
2504
+ common: {
2505
+ name: `Write state for ${id}`,
2506
+ role: 'state',
2507
+ type: common.type,
2508
+ read: common.read,
2509
+ write: common.write,
2510
+ unit: common.unit,
2511
+ },
2512
+ native: {},
2513
+ });
2514
+ } catch (e) {
2515
+ adapter.log.error(`Cannot create alias "${writeId}": ${e}`);
2418
2516
  }
2517
+ }
2518
+ }
2519
+ }
2419
2520
 
2420
- // Update meta objects
2421
- context.updateObjectContext(id, newObj);
2521
+ let obj;
2522
+ try {
2523
+ obj = await adapter.getForeignObjectAsync(id);
2524
+ } catch (err) {
2525
+ // ignore
2526
+ }
2422
2527
 
2423
- if (!isAlias && initValue !== undefined) {
2424
- if (isObject(initValue) && initValue.ack !== undefined) {
2425
- setStateHelper(sandbox, false, id, initValue, callback);
2426
- } else {
2427
- setStateHelper(sandbox, false, id, initValue, true, callback);
2428
- }
2429
- } else if (!isAlias && !forceCreation) {
2430
- setStateHelper(sandbox, false, id, null, callback);
2431
- } else if (isAlias) {
2432
- adapter.getForeignState(id, (err, state) => {
2433
- console.log('getState ' + id + ' => ' + JSON.stringify(state));
2434
- states[id] = state;
2435
- if (typeof callback === 'function') {
2436
- try {
2437
- callback.call(sandbox, null, id);
2438
- } catch (e) {
2439
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2440
- }
2441
- }
2442
- });
2443
- } else if (typeof callback === 'function') {
2444
- try {
2445
- callback.call(sandbox, null, id);
2446
- } catch (e) {
2447
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2448
- }
2528
+ if (obj &&
2529
+ obj._id &&
2530
+ validIdForAutomaticFolderCreation(obj._id) &&
2531
+ obj.type === 'folder' &&
2532
+ obj.native &&
2533
+ obj.native.autocreated === 'by automatic ensure logic'
2534
+ ) {
2535
+ // ignore default created object because we now have a more defined one
2536
+ obj = null;
2537
+ }
2538
+
2539
+ if (!obj || forceCreation) {
2540
+ // create new one
2541
+ const newObj = {
2542
+ common,
2543
+ native,
2544
+ type: 'state',
2545
+ };
2546
+ try {
2547
+ await adapter.setForeignObjectAsync(id, newObj);
2548
+ } catch (err) {
2549
+ adapter.log.warn(`Cannot set object "${id}": ${err}`);
2550
+ if (typeof callback === 'function') {
2551
+ try {
2552
+ callback.call(sandbox, err);
2553
+ } catch (e) {
2554
+ errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2449
2555
  }
2450
- await ensureObjectStructure(id);
2451
- });
2452
- } else {
2453
- if (!adapter.config.subscribe && !states[id] && states[adapter.namespace + '.' + id] === undefined) {
2454
- states[id] = {val: null, ack: true};
2455
2556
  }
2456
- // state yet exists
2557
+ return;
2558
+ }
2559
+
2560
+ // Update meta objects
2561
+ context.updateObjectContext(id, newObj);
2562
+
2563
+ if (!isAlias && initValue !== undefined) {
2564
+ if (isObject(initValue) && initValue.ack !== undefined) {
2565
+ setStateHelper(sandbox, false, id, initValue, callback);
2566
+ } else {
2567
+ setStateHelper(sandbox, false, id, initValue, true, callback);
2568
+ }
2569
+ } else if (!isAlias && !forceCreation) {
2570
+ setStateHelper(sandbox, false, id, null, callback);
2571
+ } else if (isAlias) {
2572
+ try {
2573
+ const state = await adapter.getForeignStateAsync(id);
2574
+ console.log(`getState ${id} => ${JSON.stringify(state)}`);
2575
+ states[id] = state;
2576
+ } catch (err) {
2577
+ // ignore
2578
+ }
2457
2579
  if (typeof callback === 'function') {
2458
2580
  try {
2459
2581
  callback.call(sandbox, null, id);
2460
2582
  } catch (e) {
2461
- errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2583
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
2462
2584
  }
2463
2585
  }
2464
- await ensureObjectStructure(id);
2586
+ } else if (typeof callback === 'function') {
2587
+ try {
2588
+ callback.call(sandbox, null, id);
2589
+ } catch (e) {
2590
+ errorInCallback(e); // adapter.log.error('Error in callback: ' + e)
2591
+ }
2465
2592
  }
2466
- });
2593
+ await ensureObjectStructure(id);
2594
+ } else {
2595
+ // state yet exists
2596
+ if (!adapter.config.subscribe && !states[id] && states[`${adapter.namespace}.${id}`] === undefined) {
2597
+ states[id] = {val: null, ack: true};
2598
+ }
2599
+ if (typeof callback === 'function') {
2600
+ try {
2601
+ callback.call(sandbox, null, id);
2602
+ } catch (e) {
2603
+ errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
2604
+ }
2605
+ }
2606
+
2607
+ await ensureObjectStructure(id);
2608
+ }
2467
2609
  },
2468
2610
  deleteState: function (id, callback) {
2469
2611
  // todo: check rights
@@ -2494,11 +2636,11 @@ function sandBox(script, name, verbose, debug, context) {
2494
2636
  });
2495
2637
 
2496
2638
  });
2497
- } else if (objects[adapter.namespace + '.' + id]) {
2498
- delete objects[adapter.namespace + '.' + id];
2639
+ } else if (objects[`${adapter.namespace}.${id}`]) {
2640
+ delete objects[`${adapter.namespace}.${id}`];
2499
2641
  found = true;
2500
- if (states[adapter.namespace + '.' + id]) {
2501
- delete states[adapter.namespace + '.' + id];
2642
+ if (states[`${adapter.namespace}.${id}`]) {
2643
+ delete states[`${adapter.namespace}.${id}`];
2502
2644
  }
2503
2645
 
2504
2646
  adapter.delObject(id, function (err) {
package/main.js CHANGED
@@ -143,10 +143,61 @@ function provideDeclarationsForGlobalScript(scriptID, declarations) {
143
143
  });
144
144
  }
145
145
 
146
+ // taken from here: https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset
147
+ function dstOffsetAtDate(dateInput) {
148
+ const fullYear = dateInput.getFullYear() | 0;
149
+ // "Leap Years are any year that can be exactly divided by 4 (2012, 2016, etc)
150
+ // except if it can be exactly divided by 100, then it isn't (2100, 2200, etc)
151
+ // except if it can be exactly divided by 400, then it is (2000, 2400)"
152
+ // (https://www.mathsisfun.com/leap-years.html).
153
+ const isLeapYear = ((fullYear & 3) | (fullYear/100 & 3)) === 0 ? 1 : 0;
154
+ // (fullYear & 3) = (fullYear % 4), but faster
155
+ //Alternative:var isLeapYear=(new Date(currentYear,1,29,12)).getDate()===29?1:0
156
+ const fullMonth = dateInput.getMonth() | 0;
157
+ return (
158
+ // 1. We know what the time since the Epoch really is
159
+ (+dateInput) // same as the dateInput.getTime() method
160
+ // 2. We know what the time since the Epoch at the start of the year is
161
+ - (+new Date(fullYear, 0)) // day defaults to 1 if not explicitly zeroed
162
+ // 3. Now, subtract what we would expect the time to be if daylight savings
163
+ // did not exist. This yields the time-offset due to daylight savings.
164
+ - ((
165
+ ((
166
+ // Calculate the day of the year in the Gregorian calendar
167
+ // The code below works based upon the facts of signed right shifts
168
+ // • (x) >> n: shifts n and fills in the n highest bits with 0s
169
+ // • (-x) >> n: shifts n and fills in the n highest bits with 1s
170
+ // (This assumes that x is a positive integer)
171
+ -1 + // first day in the year is day 1
172
+ (31 & ((-fullMonth) >> 4)) + // January // (-11)>>4 = -1
173
+ ((28 + isLeapYear) & ((1 - fullMonth) >> 4)) + // February
174
+ (31 & ((2 - fullMonth) >> 4)) + // March
175
+ (30 & ((3 - fullMonth) >> 4)) + // April
176
+ (31 & ((4 - fullMonth) >> 4)) + // May
177
+ (30 & ((5 - fullMonth) >> 4)) + // June
178
+ (31 & ((6 - fullMonth) >> 4)) + // July
179
+ (31 & ((7 - fullMonth) >> 4)) + // August
180
+ (30 & ((8 - fullMonth) >> 4)) + // September
181
+ (31 & ((9 - fullMonth) >> 4)) + // October
182
+ (30 & ((10 - fullMonth) >> 4)) + // November
183
+ // There are no months past December: the year rolls into the next.
184
+ // Thus, fullMonth is 0-based, so it will never be 12 in Javascript
185
+
186
+ (dateInput.getDate() | 0) // get day of the month
187
+
188
+ ) & 0xffff) * 24 * 60 // 24 hours in a day, 60 minutes in an hour
189
+ + (dateInput.getHours() & 0xff) * 60 // 60 minutes in an hour
190
+ + (dateInput.getMinutes() & 0xff)
191
+ )|0) * 60 * 1000 // 60 seconds in a minute * 1000 milliseconds in a second
192
+ - (dateInput.getSeconds() & 0xff) * 1000 // 1000 milliseconds in a second
193
+ - dateInput.getMilliseconds()
194
+ );
195
+ }
196
+
146
197
  function loadTypeScriptDeclarations() {
147
198
  // try to load the typings on disk for all 3rd party modules
148
199
  const packages = [
149
- 'node', // this provides auto completion for most builtins
200
+ 'node', // this provides auto-completion for most builtins
150
201
  'request', // preloaded by the adapter
151
202
  ];
152
203
  // Also include user-selected libraries (but only those that are also installed)
@@ -1276,12 +1327,12 @@ function timeSchedule(adapter, context) {
1276
1327
  }
1277
1328
  }
1278
1329
  if (context.timeSettings.leadingZeros && hours < 10) {
1279
- hours = '0' + hours;
1330
+ hours = `0${hours}`;
1280
1331
  }
1281
1332
  if (minutes < 10) {
1282
- minutes = '0' + minutes;
1333
+ minutes = `0${minutes}`;
1283
1334
  }
1284
- adapter.setState('variables.dayTime', hours + ':' + minutes, true);
1335
+ adapter.setState('variables.dayTime', `${hours}:${minutes}`, true);
1285
1336
  now.setMinutes(now.getMinutes() + 1);
1286
1337
  now.setSeconds(0);
1287
1338
  now.setMilliseconds(0);
@@ -1321,23 +1372,32 @@ function dayTimeSchedules(adapter, context) {
1321
1372
  sunsetTimeout = 3600000;
1322
1373
  }
1323
1374
 
1324
- let isDay;
1325
- if (sunriseTimeout < 5000) {
1326
- isDay = true;
1327
- } else if (sunsetTimeout < 5000) {
1328
- isDay = false;
1329
- } else {
1330
- // check if in between
1331
- isDay = nowDate.getTime() > (todaySunrise.getTime() - 60000) && nowDate <= todaySunset;
1332
- }
1333
-
1334
1375
  adapter.getState('variables.isDayTime', (err, state) => {
1376
+ let isDay;
1377
+ if (sunriseTimeout < 5000) {
1378
+ isDay = true;
1379
+ } else if (sunsetTimeout < 5000) {
1380
+ isDay = false;
1381
+ } else {
1382
+ // check if in between
1383
+ isDay = nowDate.getTime() > (todaySunrise.getTime() - 60000) && nowDate <= todaySunset;
1384
+ }
1385
+
1335
1386
  const val = state ? !!state.val : false;
1336
1387
  if (val !== isDay) {
1337
1388
  adapter.setState('variables.isDayTime', isDay, true);
1338
1389
  }
1339
1390
  });
1340
1391
 
1392
+ adapter.getState('variables.isDaylightSaving', (err, state) => {
1393
+ const isDayLightSaving = dstOffsetAtDate(nowDate) !== 0;
1394
+
1395
+ const val = state ? !!state.val : false;
1396
+ if (val !== isDayLightSaving) {
1397
+ adapter.setState('variables.isDaylightSaving', isDayLightSaving, true);
1398
+ }
1399
+ });
1400
+
1341
1401
  let nextTimeout = sunriseTimeout;
1342
1402
  if (sunriseTimeout > sunsetTimeout) {
1343
1403
  nextTimeout = sunsetTimeout;
@@ -2332,7 +2392,7 @@ function patchFont() {
2332
2392
  // ignore
2333
2393
  }
2334
2394
  if (!stat || stat.size !== 62324) {
2335
- const buffer = Buffer.from(JSON.parse(nodeFS.readFileSync(__dirname + '/admin-config/vsFont/codicon.json')));
2395
+ const buffer = Buffer.from(JSON.parse(nodeFS.readFileSync(`${__dirname}/admin-config/vsFont/codicon.json`)));
2336
2396
 
2337
2397
  return require('jszip').loadAsync(buffer)
2338
2398
  .then(zip => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.javascript",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "description": "Rules Engine for ioBroker",
5
5
  "author": "bluefox <dogafox@gmail.com>",
6
6
  "contributors": [