# Question re: node-red-contrib-time-range-switch

**URL:** <https://discourse.nodered.org/t/question-re-node-red-contrib-time-range-switch/97798>\
**Category:** General\
**Tags:** node-red-contrib-time-range-switch\
**Created:** [26 June 2025 01:24 UTC](https://discourse.nodered.org/t/question-re-node-red-contrib-time-range-switch/97798 "2025-06-26T01:24:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abrayshaw](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@abrayshaw](https://discourse.nodered.org/u/abrayshaw)\
**Post date:** [26 June 2025 01:24 UTC](https://discourse.nodered.org/t/question-re-node-red-contrib-time-range-switch/97798/1 "2025-06-26T01:24:12Z")

</div>

This question is specifically about the node-red-contrib-time-range-switch node. I've successfully implemented it to control a flow restricted to a time range (I'm on the USA east coast). I've set the range to 7:30 (AM) to 22:00 . Seemed to work fine at first, but then I see that sometime during the afternoon or early evening, the date has cycled to the next day. So, when I checked it at about 9PM (21:00) today, the node thinks it's filtering from 7:30 to 22:00 on the following day.  
I was presuming it would base its time on my Windows system clock. No mention anywhere about where any of the available time-related nodes get their time from. So, how do I get around this? If it's running off GMT, I just need to know that.  
Thanks

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [26 June 2025 09:09 UTC](https://discourse.nodered.org/t/question-re-node-red-contrib-time-range-switch/97798/2 "2025-06-26T09:09:30Z")

</div>

I think the node use moment() to get the current time, which is the local time  
Please correct me if i'm wrong 🙈

> <https://github.com/biddster/node-red-contrib-time-range-switch/blob/34ea40a2b62d6f7ad145ec408a8b6b79dca75e68/index.js#L180>

> **[Moment.js | Docs](https://momentjs.com/docs/#/parsing/)**

```auto
Please read:

* `moment(...)` is local mode. Ambiguous input (without offset) is assumed to be local time. Unambiguous input (with offset) is adjusted to local time.

```

[node-red-contrib-time-range-switch/index.js at 34ea40a2b62d6f7ad145ec408a8b6b79dca75e68 · biddster/node-red-contrib-time-range-switch · GitHub](https://github.com/biddster/node-red-contrib-time-range-switch/blob/34ea40a2b62d6f7ad145ec408a8b6b79dca75e68/index.js#L119)

If the end time has already passed, it shifts the entire window to the next day.

i changed my local timezone with `sudo dpkg-reconfigure tzdata`, but it doesen't affect the ouput of the node , so i can't reproduce it. 🤔

For more control what happen, i asked chatgpt to wirte me a simple function... et voilà 😉

```auto
function isNowBetween(startTimeStr, endTimeStr) {
    const now = new Date();
    const nowMinutes = now.getHours() * 60 + now.getMinutes();

    const [startHours, startMinutes] = startTimeStr.split(':').map(Number);
    const [endHours, endMinutes] = endTimeStr.split(':').map(Number);

    const startTotalMinutes = startHours * 60 + startMinutes;
    const endTotalMinutes = endHours * 60 + endMinutes;

    if (startTotalMinutes <= endTotalMinutes) {
        // Normal range (e.g., 08:00–17:00)
        return nowMinutes >= startTotalMinutes && nowMinutes < endTotalMinutes;
    } else {
        // Overnight range (e.g., 22:00–06:00)
        return nowMinutes >= startTotalMinutes || nowMinutes < endTotalMinutes;
    }
}

msg.payload = isNowBetween("05:00", "19:00")
node.send(msg)

msg.payload = isNowBetween("19:00", "05:00")
node.send(msg)

return null;

```

maybe this serve the purpose?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 September 2025 09:10 UTC](https://discourse.nodered.org/t/question-re-node-red-contrib-time-range-switch/97798/3 "2025-09-24T09:10:16Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
