Help to Evaluate Work shifts

Hi everybody, I´m newbe, I´m try to evaluate 3 Works Shifts.

The shifts must be:
Each shift must be flexible to star and finish time
They must not overlap other schedule

I'm using Input Node with Time Picker configured, this control return millis from current time.
i try to use functions to evaluate start and end time between the three shifts but the main problems occur when for example the shift numer 3 ending time at 2 am, the milis values ​​is lowest than starting milis value

somebody know if exists some node for this calculate, all help is grateful, thanks!!


ass

[{"id":"efa1a39c4a61e823","type":"tab","label":"ConfiguracionDeTurnos","disabled":false,"info":""},{"id":"062829e513f2c880","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":1,"width":3,"height":1,"name":"","label":"Turno","format":"{{msg.payload}}","layout":"row-left","x":110,"y":20,"wires":[]},{"id":"c9d3a5c8b3544c72","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":2,"width":3,"height":1,"name":"","label":"Hora Inicio","format":"{{msg.payload}}","layout":"row-left","x":270,"y":20,"wires":[]},{"id":"af8c962ddc6ccf4f","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":3,"width":3,"height":1,"name":"","label":"Hora Fin","format":"{{msg.payload}}","layout":"row-left","x":440,"y":20,"wires":[]},{"id":"d3852db22e8d77bf","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":4,"width":3,"height":1,"name":"","label":"Disponible","format":"{{msg.payload}}","layout":"row-left","x":610,"y":20,"wires":[]},{"id":"b4344aec3c3b3af7","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraIniT1","label":"","tooltip":"","group":"42675b52ac24531d","order":7,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":200,"y":160,"wires":[["955fd69c58f89cb8"]]},{"id":"507fbba248baa813","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":5,"width":3,"height":1,"name":"","label":"Aplicar","format":"{{msg.payload}}","layout":"row-left","x":790,"y":20,"wires":[]},{"id":"497c133a3acda07b","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":6,"width":3,"height":1,"name":"","label":"# 1","format":"{{msg.payload}}","layout":"row-left","x":70,"y":160,"wires":[]},{"id":"6f86c8731bb96f2f","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraFinT1","label":"","tooltip":"","group":"42675b52ac24531d","order":8,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":390,"y":160,"wires":[["f0e8eb03766b6813"]]},{"id":"bec4dee18ff9ead0","type":"ui_switch","z":"efa1a39c4a61e823","name":"HabilitadoT1","label":"","tooltip":"","group":"42675b52ac24531d","order":9,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":570,"y":160,"wires":[["4aa3d948e520bf3c"]]},{"id":"71d40fb088b5330d","type":"ui_button","z":"efa1a39c4a61e823","name":"ValidarT1","group":"42675b52ac24531d","order":10,"width":2,"height":1,"passthru":false,"label":"Validar","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":750,"y":160,"wires":[["ce06ee72e2069dc8"]]},{"id":"955fd69c58f89cb8","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraIniT1\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":220,"wires":[[]]},{"id":"f0e8eb03766b6813","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraFinT1\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":220,"wires":[[]]},{"id":"ce06ee72e2069dc8","type":"function","z":"efa1a39c4a61e823","name":"","func":"var habilitado1 = flow.get(\"HabilitadoT1\");\nvar horaini1 = flow.get(\"HoraIniT1\");\nvar horafin1 = flow.get(\"HoraFinT1\");\nvar habilitado2 = flow.get(\"HabilitadoT2\");\nvar horaini2 = flow.get(\"HoraIniT2\");\nvar horafin2 = flow.get(\"HoraFinT2\");\nvar habilitado3 = flow.get(\"HabilitadoT3\");\nvar horaini3 = flow.get(\"HoraIniT3\");\nvar horafin3 = flow.get(\"HoraFinT3\");\n\nif (habilitado1 == 0){\n    msg.payload = \"Turno 1 Deshabilitado\";\n    flow.set(\"Turno1Validado\",1);\n    return msg;\n}else{\n    if(horaini1 == horafin1){\n        msg.payload = \"Hora Inicial Igual a la Hora Final, Favor de Corregirlo!!\";\n        flow.set(\"Turno1Validado\",0);\n        return msg;\n    }else{\n        if ( horafin1 > horaini1){\n            msg.payload = \"HorarioCorrecto\";\n            flow.set(\"Turno1Validado\",1);\n            return msg;\n        }else{\n            msg.payload = \"La Hora Inicial es Mayor a la Final, El Primer Turno Disponible Debera Terminar Antes de Media Noche !!\";\n            flow.set(\"Turno1Validado\",0);\n            return msg; \n        }\n    }        \n\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":810,"y":220,"wires":[["f3ed6692f7ac840b"]]},{"id":"4aa3d948e520bf3c","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HabilitadoT1\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":220,"wires":[[]]},{"id":"489e3a67c80f1cb8","type":"inject","z":"efa1a39c4a61e823","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":410,"y":120,"wires":[["bec4dee18ff9ead0","c3dab055e9dd4ef1"]]},{"id":"f3ed6692f7ac840b","type":"ui_toast","z":"efa1a39c4a61e823","position":"dialog","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":false,"topic":"","name":"","x":1030,"y":340,"wires":[[]]},{"id":"6fd93256bd929540","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraIniT2","label":"","tooltip":"","group":"42675b52ac24531d","order":13,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":200,"y":320,"wires":[["68c207a6ecec9884"]]},{"id":"e593b250be16d6ee","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":12,"width":3,"height":1,"name":"","label":"# 2","format":"{{msg.payload}}","layout":"row-left","x":70,"y":320,"wires":[]},{"id":"de0876a5ac849134","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraFinT2","label":"","tooltip":"","group":"42675b52ac24531d","order":14,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":370,"y":320,"wires":[["e5e3cc699b8150c9"]]},{"id":"c3dab055e9dd4ef1","type":"ui_switch","z":"efa1a39c4a61e823","name":"HabilitadoT2","label":"","tooltip":"","group":"42675b52ac24531d","order":15,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":550,"y":320,"wires":[["7d0e903012e5b394"]]},{"id":"3287e8796d5bfd4f","type":"ui_button","z":"efa1a39c4a61e823","name":"ValidarT2","group":"42675b52ac24531d","order":16,"width":2,"height":1,"passthru":false,"label":"Validar","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":730,"y":320,"wires":[["3fabe47c3329028d"]]},{"id":"68c207a6ecec9884","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraIniT2\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":380,"wires":[[]]},{"id":"e5e3cc699b8150c9","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraFinT2\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":380,"wires":[[]]},{"id":"3fabe47c3329028d","type":"function","z":"efa1a39c4a61e823","name":"","func":"var habilitado1 = flow.get(\"HabilitadoT1\");\nvar horaini1 = flow.get(\"HoraIniT1\");\nvar horafin1 = flow.get(\"HoraFinT1\");\nvar habilitado2 = flow.get(\"HabilitadoT2\");\nvar horaini2 = flow.get(\"HoraIniT2\");\nvar horafin2 = flow.get(\"HoraFinT2\");\nvar habilitado3 = flow.get(\"HabilitadoT3\");\nvar horaini3 = flow.get(\"HoraIniT3\");\nvar horafin3 = flow.get(\"HoraFinT3\");\n\nif (habilitado2 == 0){\n    msg.payload = \"Turno 2 Deshabilitado\";\n    flow.set(\"Turno2Validado\",1);\n    return msg;\n}else{\n    if(horaini2 == horafin2){\n        msg.payload = \"Hora Inicial Igual a la Hora Final, Favor de Corregirlo!!\";\n        flow.set(\"Turno2Validado\",0);\n        return msg;\n    }else{\n        if (flow.get(\"Turno1Validado\") == 1){\n            if (habilitado1 == 1) {\n                if ( horaini2 >= horafin1 || horaini2 < horaini1 ){\n                    msg.payload = \"HorarioCorrecto\";\n                    flow.set(\"Turno2Validado\",1);\n                    return msg;\n                }else{\n                    msg.payload = \"Turnos Traslapados, Favor de Revisar!!\";\n                    flow.set(\"Turno2Validado\",0);\n                    return msg; \n                }\n            }else{\n                if ( horafin2 > horaini2){\n                    msg.payload = \"HorarioCorrecto\";\n                    flow.set(\"Turno2Validado\",1);\n                    return msg;\n                }else{\n                    msg.payload = \"La Hora Inicial es Mayor a la Final, El Primer Turno Disponible Debera Terminar Antes de Media Noche !!\";\n                    flow.set(\"Turno2Validado\",0);\n                    return msg; \n                }                \n            }    \n        }else{\n            msg.payload = \"El Turno 1 Debera ser valido o No Disponible antes de validar los posteriores\";\n            flow.set(\"Turno2Validado\",0);\n            return msg;  \n        }    \n    }        \n\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":380,"wires":[["f3ed6692f7ac840b"]]},{"id":"7d0e903012e5b394","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HabilitadoT2\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":380,"wires":[[]]},{"id":"9124e79f3f426d5c","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraIniT3","label":"","tooltip":"","group":"42675b52ac24531d","order":19,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":200,"y":460,"wires":[["d20a00955a050e92"]]},{"id":"5bf60dfe6b4b83c3","type":"ui_text","z":"efa1a39c4a61e823","group":"42675b52ac24531d","order":18,"width":3,"height":1,"name":"","label":"# 3","format":"{{msg.payload}}","layout":"row-left","x":70,"y":460,"wires":[]},{"id":"e832f3401ef41114","type":"ui_text_input","z":"efa1a39c4a61e823","name":"HoraFinT3","label":"","tooltip":"","group":"42675b52ac24531d","order":20,"width":3,"height":1,"passthru":true,"mode":"time","delay":300,"topic":"topic","topicType":"msg","x":370,"y":460,"wires":[["d5c6e3a851c0aaac"]]},{"id":"50778dc6a0842c1b","type":"ui_switch","z":"efa1a39c4a61e823","name":"HabilitadoT3","label":"","tooltip":"","group":"42675b52ac24531d","order":21,"width":3,"height":1,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":550,"y":460,"wires":[["809225dc802b8869"]]},{"id":"89abf6543fb602ce","type":"ui_button","z":"efa1a39c4a61e823","name":"ValidarT3","group":"42675b52ac24531d","order":22,"width":2,"height":1,"passthru":false,"label":"Validar","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":730,"y":460,"wires":[["89ee6f57f7c98cb9"]]},{"id":"d20a00955a050e92","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraIniT3\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":520,"wires":[[]]},{"id":"d5c6e3a851c0aaac","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HoraFinT3\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":520,"wires":[[]]},{"id":"89ee6f57f7c98cb9","type":"function","z":"efa1a39c4a61e823","name":"","func":"var habilitado = flow.get(\"HabilitadoT1\");\nvar horaini = flow.get(\"HoraIniT1\");\nvar horafin = flow.get(\"HoraFinT1\");\nvar habilitado2 = flow.get(\"HabilitadoT2\");\nvar horaini2 = flow.get(\"HoraIniT2\");\nvar horafin2 = flow.get(\"HoraFinT2\");\nvar habilitado3 = flow.get(\"HabilitadoT3\");\nvar horaini3 = flow.get(\"HoraIniT3\");\nvar horafin3 = flow.get(\"HoraFinT3\");\n\nif (habilitado3 == 0){\n    msg.payload = \"Turno 3 Deshabilitado\";\n    flow.set(\"Turno3Validado\",1);\n    return msg;\n}else{\n    if(horaini3 == horafin3){\n        msg.payload = \"Hora Inicial Igual a la Hora Final, Favor de Corregirlo!!\";\n        flow.set(\"Turno3Validado\",0);\n        return msg;\n    }else{\n        if (flow.get(\"Turno2Validado\") == 1 && flow.get(\"Turno1Validado\") == 1 ){\n            if (habilitado2 == 1) {\n                if ( horaini3 >= horafin2 || horaini3 < horaini1){\n                    msg.payload = \"HorarioCorrecto\";\n                    flow.set(\"Turno3Validado\",1);\n                    return msg;\n                }else{\n                    msg.payload = \"Turnos Traslapados, Favor de Revisar!!\";\n                    flow.set(\"Turno3Validado\",0);\n                    return msg; \n                }\n            }else{\n                if ( horafin3 > horaini3){\n                    msg.payload = \"HorarioCorrecto\";\n                    flow.set(\"Turno3Validado\",1);\n                    return msg;\n                }else{\n                    msg.payload = \"La Hora Inicial es Mayor a la Final, El Primer Turno Disponible Debera Terminar Antes de Media Noche !!\";\n                    flow.set(\"Turno3Validado\",0);\n                    return msg; \n                }                \n            }    \n        }else{\n            msg.payload = \"El Turno 1 y 2 Deberan ser validos o No Disponibles antes de validar los posteriores\";\n            flow.set(\"Turno3Validado\",0);\n            return msg;  \n        }    \n    }        \n\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":790,"y":520,"wires":[["f3ed6692f7ac840b"]]},{"id":"809225dc802b8869","type":"function","z":"efa1a39c4a61e823","name":"","func":"var numer = msg.payload;\nflow.set(\"HabilitadoT3\",numer);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":520,"wires":[[]]},{"id":"42675b52ac24531d","type":"ui_group","name":"Conf.Turnos","tab":"39e0d0de.1be26","order":9,"disp":true,"width":"15","collapse":false},{"id":"39e0d0de.1be26","type":"ui_tab","name":"Configuracion","icon":"dashboard","order":4,"disabled":false,"hidden":false}]