diff --git a/README.md b/README.md
index 6a801d8..32c5229 100644
--- a/README.md
+++ b/README.md
@@ -56,8 +56,8 @@ SOFTWARE.
## Attribution
The following icons have been taken from Node-RED provided nodes:
-* Timer icon (delay node)
-* Switch icon (switch node)
+* Timer icon (Node-RED delay node)
+* Switch icon (Node-RED switch node)
The following icons have been taken from Flaticon:
* Hour glass icon made by Freepik from www.flaticon.com
diff --git a/nodes/delay.html b/nodes/delay.html
index 1bd05f2..2f10afc 100644
--- a/nodes/delay.html
+++ b/nodes/delay.html
@@ -38,11 +38,11 @@
-
+
-
+
diff --git a/nodes/locales/en-US/config.json b/nodes/locales/en-US/config.json
index d36c1ac..895c63d 100644
--- a/nodes/locales/en-US/config.json
+++ b/nodes/locales/en-US/config.json
@@ -10,7 +10,9 @@
"time": "Time of Day",
"sun": "Sun Position",
"moon": "Moon Position",
- "fullMessage": "full message"
+ "fullMessage": "full message",
+ "offset": "Offset",
+ "random": "Randomized"
},
"list":
{
diff --git a/nodes/locales/en-US/delay.json b/nodes/locales/en-US/delay.json
index fbf6c89..2862626 100644
--- a/nodes/locales/en-US/delay.json
+++ b/nodes/locales/en-US/delay.json
@@ -5,9 +5,7 @@
{
"outputPort": "delayed message",
"min": " min.",
- "when": "When",
- "offset": "Offset",
- "random": "Randomized"
+ "when": "When"
},
"status":
{
diff --git a/nodes/switch.html b/nodes/switch.html
index 4873ad3..eefc2dd 100644
--- a/nodes/switch.html
+++ b/nodes/switch.html
@@ -82,7 +82,7 @@
},
conditions:
{
- value: [{operator: "before", operands: {type: "time", value: ""}, label: ""}]
+ value: [{operator: "before", operands: {type: "time", value: "", offset: 0, random: false}, label: ""}]
},
stopOnFirstMatch:
{
@@ -200,9 +200,33 @@
options: moonTimes
};
+ const offsetInput =
+ {
+ min: -300,
+ max: 300,
+ step: 5,
+ change: function(event, ui)
+ {
+ var value = parseInt(this.value, 10);
+ var min = $(this).spinner("option", "min");
+ var max = $(this).spinner("option", "max");
+ if (isNaN(value) ||
+ (value < min))
+ {
+ $(this).spinner("value", min);
+ }
+ else if (value > max)
+ {
+ $(this).spinner("value", max);
+ }
+ }
+ };
+
let fragment = document.createDocumentFragment();
let operatorBox = $("
", {style: "display: inline-block; vertical-align: middle; width: auto;"}).appendTo(fragment);
- let operandBox = $("
", {style: "display: inline-block; vertical-align: middle; width: auto; padding-left: 2px;"}).appendTo(fragment);
+ let timeBox = $("
", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 2px;"}).appendTo(fragment);
+ let weekdaysBox = $("
", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 2px;"}).appendTo(fragment);
+ let monthsBox = $("
", {style: "display: inline-block; vertical-align: middle; width: auto; margin-left: 2px;"}).appendTo(fragment);
$("
", {class: "node-input-index", style: "position: absolute; width: auto; top: 50%; right: 26px; margin-top: -9px;"})
.html("→ " + (index + 1))
.appendTo(fragment);
@@ -216,117 +240,140 @@
.append($(" ").val("months").text(node._("node-red-contrib-chronos/chronos-config:common.list.operator.months")))
.appendTo(operatorBox);
- let subRow1 = $("
").appendTo(operandBox);
- let subRow2 = $("
", {style: "margin-top: 5px;"}).appendTo(operandBox);
- let subRow3 = $("
", {style: "margin-top: 5px;"}).appendTo(operandBox);
-
- let time1 = $(" ", {type: "text", class: "node-input-time1", style: "margin-left: 4px"})
- .appendTo(subRow1)
+ let time1Box = $("
", {style: "margin-left: 4px;"}).appendTo(timeBox);
+ let time2Box = $("
", {style: "margin-left: 4px; margin-top: 5px;"}).appendTo(timeBox);
+ let time1Row1 = $("
").appendTo(time1Box);
+ let time1Row2 = $("
", {style: "margin-top: 5px;"}).appendTo(time1Box);
+ let time2Row1 = $("
").appendTo(time2Box);
+ let time2Row2 = $("
", {style: "margin-top: 5px;"}).appendTo(time2Box);
+ let monthsRow1 = $("
").appendTo(monthsBox);
+ let monthsRow2 = $("
", {style: "margin-top: 5px;"}).appendTo(monthsBox);
+ let monthsRow3 = $("
", {style: "margin-top: 5px;"}).appendTo(monthsBox);
+
+ let time1 = $(" ", {type: "text", class: "node-input-time1"})
+ .appendTo(time1Row1)
.typedInput({types: [timeInput, sunTimeInput, moonTimeInput]});
time1.typedInput("width", "280px");
+ let extend1 = $(" ", {href: "#", style: "margin-left: 6px;"})
+ .html(" ")
+ .appendTo(time1Row1);
- let time2 = $(" ", {type: "text", class: "node-input-time2", style: "margin-left: 4px;"})
- .appendTo(subRow2)
+ let time2 = $(" ", {type: "text", class: "node-input-time2"})
+ .appendTo(time2Row1)
.typedInput({types: [timeInput, sunTimeInput, moonTimeInput]});
time2.typedInput("width", "280px");
+ let extend2 = $(" ", {href: "#", style: "margin-left: 6px;"})
+ .html(" ")
+ .appendTo(time2Row1);
+
+ $(" ", {style: "width: auto; margin-right: 6px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.label.offset"))
+ .appendTo(time1Row2);
+ let offset1 = $(" ", {class: "node-input-offset1", style: "width: 50px;"})
+ .appendTo(time1Row2)
+ .spinner(offsetInput);
+ let random1 = $(" ", {type: "checkbox", class: "node-input-random1", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
+ .appendTo(time1Row2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.label.random"))
+ .appendTo(time1Row2);
+
+ $(" ", {style: "width: auto; margin-right: 6px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.label.offset"))
+ .appendTo(time2Row2);
+ let offset2 = $(" ", {class: "node-input-offset2", style: "width: 50px;"})
+ .appendTo(time2Row2)
+ .spinner(offsetInput);
+ let random2 = $(" ", {type: "checkbox", class: "node-input-random2", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
+ .appendTo(time2Row2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.label.random"))
+ .appendTo(time2Row2);
- let weekdays = $("
", {style: "display: inline-block; width: auto;"})
- .appendTo(subRow1);
let monday = $(" ", {type: "checkbox", class: "node-input-monday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.monday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.monday")).appendTo(weekdaysBox);
let tuesday = $(" ", {type: "checkbox", class: "node-input-tuesday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.tuesday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.tuesday")).appendTo(weekdaysBox);
let wednesday = $(" ", {type: "checkbox", class: "node-input-wednesday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.wednesday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.wednesday")).appendTo(weekdaysBox);
let thursday = $(" ", {type: "checkbox", class: "node-input-thursday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.thursday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.thursday")).appendTo(weekdaysBox);
let friday = $(" ", {type: "checkbox", class: "node-input-friday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.friday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.friday")).appendTo(weekdaysBox);
let saturday = $(" ", {type: "checkbox", class: "node-input-saturday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.saturday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.saturday")).appendTo(weekdaysBox);
let sunday = $(" ", {type: "checkbox", class: "node-input-sunday", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(weekdays);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: auto;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.sunday")).appendTo(weekdays);
+ .appendTo(weekdaysBox);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: auto;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.weekday.sunday")).appendTo(weekdaysBox);
- let months1 = $("
", {style: "display: inline-block; width: auto;"})
- .appendTo(subRow1);
let january = $(" ", {type: "checkbox", class: "node-input-january", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months1);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.january")).appendTo(months1);
+ .appendTo(monthsRow1);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.january")).appendTo(monthsRow1);
let february = $(" ", {type: "checkbox", class: "node-input-february", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months1);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.february")).appendTo(months1);
+ .appendTo(monthsRow1);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.february")).appendTo(monthsRow1);
let march = $(" ", {type: "checkbox", class: "node-input-march", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months1);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.march")).appendTo(months1);
+ .appendTo(monthsRow1);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.march")).appendTo(monthsRow1);
let april = $(" ", {type: "checkbox", class: "node-input-april", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months1);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.april")).appendTo(months1);
- let months2 = $("
", {style: "display: inline-block; width: auto;"})
- .appendTo(subRow2);
+ .appendTo(monthsRow1);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.april")).appendTo(monthsRow1);
let may = $(" ", {type: "checkbox", class: "node-input-may", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months2);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.may")).appendTo(months2);
+ .appendTo(monthsRow2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.may")).appendTo(monthsRow2);
let june = $(" ", {type: "checkbox", class: "node-input-june", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months2);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.june")).appendTo(months2);
+ .appendTo(monthsRow2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.june")).appendTo(monthsRow2);
let july = $(" ", {type: "checkbox", class: "node-input-july", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months2);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.july")).appendTo(months2);
+ .appendTo(monthsRow2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.july")).appendTo(monthsRow2);
let august = $(" ", {type: "checkbox", class: "node-input-august", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months2);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.august")).appendTo(months2);
- let months3 = $("
", {style: "display: inline-block; width: auto;"})
- .appendTo(subRow3);
+ .appendTo(monthsRow2);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.august")).appendTo(monthsRow2);
let september = $(" ", {type: "checkbox", class: "node-input-september", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months3);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.september")).appendTo(months3);
+ .appendTo(monthsRow3);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.september")).appendTo(monthsRow3);
let october = $(" ", {type: "checkbox", class: "node-input-october", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months3);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.october")).appendTo(months3);
+ .appendTo(monthsRow3);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.october")).appendTo(monthsRow3);
let november = $(" ", {type: "checkbox", class: "node-input-november", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months3);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.november")).appendTo(months3);
+ .appendTo(monthsRow3);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.november")).appendTo(monthsRow3);
let december = $(" ", {type: "checkbox", class: "node-input-december", style: "width: auto; margin-top: 0px; margin-bottom: 1px; margin-left: 6px;"})
- .appendTo(months3);
- $(" ", {style: "padding-left: 4px; margin-bottom: 0px; width: 40px;"})
- .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.december")).appendTo(months3);
+ .appendTo(monthsRow3);
+ $(" ", {style: "margin-left: 4px; margin-bottom: 0px; width: 40px;"})
+ .text(node._("node-red-contrib-chronos/chronos-config:common.list.month.december")).appendTo(monthsRow3);
operator.change(function()
{
- time1.typedInput("hide");
- time2.typedInput("hide");
- weekdays.hide();
- months1.hide();
- months2.hide();
- months3.hide();
-
- subRow2.hide();
- subRow3.hide();
+ timeBox.hide();
+ time2Box.hide();
+ weekdaysBox.hide();
+ monthsBox.hide();
var value = $(this).val();
switch (value)
@@ -334,37 +381,89 @@
case "before":
case "after":
{
- time1.typedInput("show");
+ timeBox.show();
break;
}
case "between":
case "outside":
{
- time1.typedInput("show");
- time2.typedInput("show");
- subRow2.show();
+ timeBox.show();
+ time2Box.show();
break;
}
case "weekdays":
{
- weekdays.show();
+ weekdaysBox.show();
break;
}
case "months":
{
- months1.show();
- months2.show();
- months3.show();
- subRow2.show();
- subRow3.show();
+ monthsBox.show();
break;
}
}
});
+ function showExtensionRow1()
+ {
+ time1Row2.show();
+ extend1.html(" ");
+ }
+
+ function hideExtensionRow1()
+ {
+ time1Row2.hide();
+ extend1.html(" ");
+
+ offset1.spinner("value", 0);
+ random1.prop("checked", false);
+ }
+
+ function showExtensionRow2()
+ {
+ time2Row2.show();
+ extend2.html(" ");
+ }
+
+ function hideExtensionRow2()
+ {
+ time2Row2.hide();
+ extend2.html(" ");
+
+ offset2.spinner("value", 0);
+ random2.prop("checked", false);
+ }
+
+ extend1.click(function()
+ {
+ if (time1Row2.is(":hidden"))
+ {
+ showExtensionRow1();
+ }
+ else
+ {
+ hideExtensionRow1();
+ }
+ });
+
+ extend2.click(function()
+ {
+ if (time2Row2.is(":hidden"))
+ {
+ showExtensionRow2();
+ }
+ else
+ {
+ hideExtensionRow2();
+ }
+ });
+
+ hideExtensionRow1();
+ hideExtensionRow2();
+
if (!("operator" in data))
{
- data = {operator: "before", operands: {type: "time", value: ""}, label: ""};
+ data = {operator: "before", operands: {type: "time", value: "", offset: 0, random: false}, label: ""};
}
operator.val(data.operator);
@@ -373,6 +472,12 @@
{
time1.typedInput("type", data.operands.type);
time1.typedInput("value", data.operands.value);
+ if (data.operands.offset != 0)
+ {
+ offset1.spinner("value", data.operands.offset);
+ random1.prop("checked", data.operands.random);
+ showExtensionRow1();
+ }
}
else if ((data.operator == "between") || (data.operator == "outside"))
{
@@ -380,6 +485,18 @@
time1.typedInput("value", data.operands[0].value);
time2.typedInput("type", data.operands[1].type);
time2.typedInput("value", data.operands[1].value);
+ if (data.operands[0].offset != 0)
+ {
+ offset1.spinner("value", data.operands[0].offset);
+ random1.prop("checked", data.operands[0].random);
+ showExtensionRow1();
+ }
+ if (data.operands[1].offset != 0)
+ {
+ offset2.spinner("value", data.operands[1].offset);
+ random2.prop("checked", data.operands[1].random);
+ showExtensionRow2();
+ }
}
else if (data.operator == "weekdays")
{
@@ -474,6 +591,10 @@
let operator = $(this).find(".node-input-operator");
let time1 = $(this).find(".node-input-time1");
let time2 = $(this).find(".node-input-time2");
+ let offset1 = $(this).find(".node-input-offset1");
+ let offset2 = $(this).find(".node-input-offset2");
+ let random1 = $(this).find(".node-input-random1");
+ let random2 = $(this).find(".node-input-random2");
let monday = $(this).find(".node-input-monday");
let tuesday = $(this).find(".node-input-tuesday");
let wednesday = $(this).find(".node-input-wednesday");
@@ -502,6 +623,8 @@
data.operands = {};
data.operands.type = time1.typedInput("type");
data.operands.value = time1.typedInput("value");
+ data.operands.offset = offset1.spinner("value");
+ data.operands.random = random1.prop("checked");
if (data.operands.type == "time")
{
@@ -517,8 +640,12 @@
data.operands = [{}, {}];
data.operands[0].type = time1.typedInput("type");
data.operands[0].value = time1.typedInput("value");
+ data.operands[0].offset = offset1.spinner("value");
+ data.operands[0].random = random1.prop("checked");
data.operands[1].type = time2.typedInput("type");
data.operands[1].value = time2.typedInput("value");
+ data.operands[1].offset = offset2.spinner("value");
+ data.operands[1].random = random2.prop("checked");
data.label += " ";
if (data.operands[0].type == "time")
diff --git a/nodes/switch.js b/nodes/switch.js
index 5dfd46f..16f9b0b 100644
--- a/nodes/switch.js
+++ b/nodes/switch.js
@@ -93,6 +93,12 @@ module.exports = function(RED)
{
let targetTime = time.getTime(now.clone(), cond.operands.type, cond.operands.value);
+ if (cond.operands.offset != 0)
+ {
+ let offset = cond.operands.random ? Math.round(Math.random() * cond.operands.offset) : cond.operands.offset;
+ targetTime.add(offset, "minutes");
+ }
+
node.debug("Check if " + cond.operator + " " + targetTime.format("YYYY-MM-DD HH:mm:ss"));
if (((cond.operator == "before") && now.isBefore(targetTime)) ||
((cond.operator == "after") && now.isSameOrAfter(targetTime)))
@@ -105,6 +111,17 @@ module.exports = function(RED)
let time1 = time.getTime(now.clone(), cond.operands[0].type, cond.operands[0].value);
let time2 = time.getTime(now.clone(), cond.operands[1].type, cond.operands[1].value);
+ if (cond.operands[0].offset != 0)
+ {
+ let offset = cond.operands[0].random ? Math.round(Math.random() * cond.operands[0].offset) : cond.operands[0].offset;
+ time1.add(offset, "minutes");
+ }
+ if (cond.operands[1].offset != 0)
+ {
+ let offset = cond.operands[1].random ? Math.round(Math.random() * cond.operands[1].offset) : cond.operands[1].offset;
+ time2.add(offset, "minutes");
+ }
+
if (time2.isSameOrBefore(time1))
{
if (cond.operands[1].type == "time")