Action between two time strings

Hi There - I don't suppose there is an easy way to do this, I have 2 messages, one with a start time and one with an end time. I'd like to trigger a response/set a global message if the start and end time are within the current time.. does this make sense? My Node red skills are pretty poor but am trying!

[
    {
        "id": "14aabb1a.e5d4a5",
        "type": "tab",
        "label": "Octopus Agile",
        "disabled": false,
        "info": ""
    },
    {
        "id": "5fbec1e803d8affe",
        "type": "exec",
        "z": "14aabb1a.e5d4a5",
        "command": "python3 C:\\data\\Intelligent.py",
        "addpay": false,
        "append": "",
        "useSpawn": "true",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 800,
        "y": 300,
        "wires": [
            [
                "b746e564625d7942"
            ],
            [],
            []
        ]
    },
    {
        "id": "d9b881bcbf47a662",
        "type": "inject",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 540,
        "y": 300,
        "wires": [
            [
                "5fbec1e803d8affe"
            ]
        ]
    },
    {
        "id": "9c0e3991c5b122fb",
        "type": "debug",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1770,
        "y": 260,
        "wires": []
    },
    {
        "id": "b746e564625d7942",
        "type": "split",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "splt": ",",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 1050,
        "y": 280,
        "wires": [
            [
                "69a76f6ba6ad1639"
            ]
        ]
    },
    {
        "id": "69a76f6ba6ad1639",
        "type": "join",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "num",
        "reduceFixup": "",
        "x": 1250,
        "y": 280,
        "wires": [
            [
                "c7125c80bee630b5",
                "e655eb5323e137e4"
            ]
        ]
    },
    {
        "id": "c7125c80bee630b5",
        "type": "change",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload[0]",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1440,
        "y": 260,
        "wires": [
            [
                "c308d480c5647904"
            ]
        ]
    },
    {
        "id": "c308d480c5647904",
        "type": "string",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "methods": [
            {
                "name": "between",
                "params": [
                    {
                        "type": "str",
                        "value": "\"nextRunStart\": \""
                    },
                    {
                        "type": "str",
                        "value": ":00+00:00\""
                    }
                ]
            }
        ],
        "prop": "payload",
        "propout": "payload",
        "object": "msg",
        "objectout": "msg",
        "x": 1610,
        "y": 260,
        "wires": [
            [
                "9c0e3991c5b122fb"
            ]
        ]
    },
    {
        "id": "d336940e73599754",
        "type": "debug",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1770,
        "y": 320,
        "wires": []
    },
    {
        "id": "e655eb5323e137e4",
        "type": "change",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload[1]",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1440,
        "y": 320,
        "wires": [
            [
                "0535d0b676e9eac2"
            ]
        ]
    },
    {
        "id": "0535d0b676e9eac2",
        "type": "string",
        "z": "14aabb1a.e5d4a5",
        "name": "",
        "methods": [
            {
                "name": "between",
                "params": [
                    {
                        "type": "str",
                        "value": " \"nextRunEnd\": \""
                    },
                    {
                        "type": "str",
                        "value": ":00+00:00\""
                    }
                ]
            }
        ],
        "prop": "payload",
        "propout": "payload",
        "object": "msg",
        "objectout": "msg",
        "x": 1610,
        "y": 320,
        "wires": [
            [
                "d336940e73599754"
            ]
        ]
    },
    {
        "id": "d92e6fbc84e11bd3",
        "type": "inject",
        "z": "14aabb1a.e5d4a5",
        "name": "Sample returned string from script",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{     \"nextRunStart\": \"2022-11-03 23:30:00+00:00\",     \"nextRunEnd\": \"2022-11-04 06:30:00+00:00\",     \"timesObj\": [         {             \"startDt\": \"2022-11-03 23:30:00+00:00\",             \"endDt\": \"2022-11-04 06:30:00+00:00\"         }     ],     \"updatedAt\": \"2022-11-03 21:06:45.308625+00:00\" }",
        "payloadType": "str",
        "x": 780,
        "y": 240,
        "wires": [
            [
                "b746e564625d7942"
            ]
        ]
    },
    {
        "id": "4186ce1216c2f68f",
        "type": "comment",
        "z": "14aabb1a.e5d4a5",
        "name": "Splits the string for extracting the paths",
        "info": "",
        "x": 1150,
        "y": 220,
        "wires": []
    }
]

Could you please explain more on this one? Do you mean start and end time are same? Then trigger an action? If yes then request you to kindly do mention your node-red json code in your if possible so that we can get a glimpse of what's going on, cheers.

Thanks,
Ravinder Singh

@wofforduk welcome to the forum.

First your flow wouldn't import so I edited it so it would (see note at end of this post)

Looking at the data in the inject node, it looks like your python program is returning a json string. If you push it thru a json object, this is what you get:
Screen Shot 2022-11-04 at 3.17.37 AM
Notice all the dates are strings. To compare them you could use
x = Date(string_date)
here is a function node that will change all the date strings in your object to milliseconds.

let nextRunStart = msg.payload.nextRunStart
let nextRunEnd = msg.payload.nextRunEnd
let updatedAt = msg.payload.updatedAt

let startDt = msg.payload.timesObj[0].startDt
let endDt = msg.payload.timesObj[0].endDt


msg.payload.nextRunStart = Date.parse(nextRunStart)
msg.payload.nextRunEnd = Date.parse(nextRunEnd)
msg.payload.updatedAt = Date.parse(updatedAt)

msg.payload.timesObj[0].startDt = Date.parse(startDt)
msg.payload.timesObj[0].endDt = Date.parse(endDt)

return msg;

or you might want to edit your python code to return the values as time to eliminate the need for the conversion in your flow.

hopefully this will help you deal with the rest of your flow.

[{"id":"d92e6fbc84e11bd3","type":"inject","z":"14aabb1a.e5d4a5","name":"Sample returned string from script","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{     \"nextRunStart\": \"2022-11-03 23:30:00+00:00\",     \"nextRunEnd\": \"2022-11-04 06:30:00+00:00\",     \"timesObj\": [         {             \"startDt\": \"2022-11-03 23:30:00+00:00\",             \"endDt\": \"2022-11-04 06:30:00+00:00\"         }     ],     \"updatedAt\": \"2022-11-03 21:06:45.308625+00:00\" }","payloadType":"str","x":380,"y":80,"wires":[["b746e564625d7942","601afc07663aa8ef","3f276b67bf9c7e76"]]},{"id":"601afc07663aa8ef","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 30","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":600,"y":120,"wires":[]},{"id":"31fffee69014e9dc","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 31","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":120,"wires":[]},{"id":"cd8bc32f1068860e","type":"debug","z":"14aabb1a.e5d4a5","name":"debug 33","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":960,"y":80,"wires":[]},{"id":"3f276b67bf9c7e76","type":"json","z":"14aabb1a.e5d4a5","name":"","property":"payload","action":"","pretty":false,"x":610,"y":80,"wires":[["31fffee69014e9dc","3a3c7f285f6e9793"]]},{"id":"3a3c7f285f6e9793","type":"function","z":"14aabb1a.e5d4a5","name":"function 3","func":"let nextRunStart = msg.payload.nextRunStart\nlet nextRunEnd = msg.payload.nextRunEnd\nlet updatedAt = msg.payload.updatedAt\n\nlet startDt = msg.payload.timesObj[0].startDt\nlet endDt = msg.payload.timesObj[0].endDt\n\n\nmsg.payload.nextRunStart = Date.parse(nextRunStart)\nmsg.payload.nextRunEnd = Date.parse(nextRunEnd)\nmsg.payload.updatedAt = Date.parse(updatedAt)\n\nmsg.payload.timesObj[0].startDt = Date.parse(startDt)\nmsg.payload.timesObj[0].endDt = Date.parse(endDt)\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":80,"wires":[["cd8bc32f1068860e"]]}]



In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Thank you! that has certainly cleaned my flow up really well! and thanks for the tips on posting code - im a bit new here!

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