Code help
Okay I am fighting with the syntax of this code more than the logic of it, I BELIEVE, I am trying to increment hours accordingly. What I mean by this is if the store type is a Walmart or a Sam's club and it falls outside of the hours of operation I want to add time to it. I would really prefer to make it the next time they are opened, but I can play with that later. For example a WO came in at 3:05am on 6/14/2023 and due to the priority and a barrier code, irreverent abstraction for this, it adds 18hrs to the time. The time then lands at 7:05pm which is right outside of the range of open hours for Sam's club, therefore it should 14 hrs to the time to make it fall within that range. If that makes any sense, but my code is acting like 7:05pm is within the range. Please advise:
Code:
//Now that the corrected time has been handed off to this field it will check based on if its a SAMs club or a Walmart if the hours fall during closing time. If they do then it will add the corresponding amount of hours to it.
//Declare the variables so the hours can be changed later if needed
var duration samshrs = Hours(12);
var duration walmarthrs = Hours(8);
var TimeOfDay samsclose = ToTimeOfDay("7:00pm");
var TimeOfDay samsopen = ToTimeOfDay("9:00am");
var TimeOfDay walmartclose = ToTimeOfDay("11:00pm");
var TimeOfDay walmartopen = ToTimeOfDay("6:00am");
//If then statement to increment the hours if they fall within non-working hours.
If([Project Site - Store Type] = "Wholesale (Sam's Club)" and ((ToTimeOfDay([Work Order Request Recieved Date/Time] + [Duration Counter]) >= $samsclose) and (ToTimeOfDay([Work Order Request Recieved Date/Time] + [Duration Counter]) < $samsopen)), ([Work Order Request Recieved Date/Time] + [Duration Counter] + $samshrs),
If([Project Site - Store Type] = "Retail (Walmart)" and ((ToTimeOfDay([Work Order Request Recieved Date/Time] + [Duration Counter]) >= $walmartclose) and (ToTimeOfDay([Work Order Request Recieved Date/Time] + [Duration Counter]) < $walmartopen)), ([Work Order Request Recieved Date/Time] + [Duration Counter] + $walmarthrs),
([Work Order Request Recieved Date/Time] + [Duration Counter])))
------------------------------
William Hunter
------------------------------