Difference between revisions of "Check if within Working hours"

From Keyfax Wiki
Jump to: navigation, search
(Created page with "The example below uses a Date databox to check if it is currently out of hours, if it's not we know it is currently working hours. In this example the working hours are defi...")
(No difference)

Revision as of 16:41, 7 March 2018

The example below uses a Date databox to check if it is currently out of hours, if it's not we know it is currently working hours.

In this example the working hours are defined as.

Days: Monday - Friday Hours: 8:00am - 6:00pm Closed on Bank Holidays: 24th March, 25th December, 26th December.




This can be determined in one expression.

WeekDay Inlist("1,7",",") OR ds AsDate Format('HHmm') Between('0000','0800') OR ds AsDate Format('HHmm') Between('1800','2359') OR ds AsDate Format ('dd/MM') InList("24/03,25/12,26/12",",") Breaking the expression down into the various parts we can see what each is doing.


WeekDay Inlist("1,7",",")

This is checking if the day is 1 or 7. This is because the WeekDay is represented the following way:
Sunday = 1
Monday = 2
Tuesday = 3
Wednesday = 4
Thursday = 5
Friday = 6
Saturday = 7
So if it's Saturday or Sunday then 1 or 7 will be the value and this is being checked for with the Inlist expression.

OR

OR is used to say if any of the various parts of the expression come back as true then the whole expression is true. If A OR B OR C OR D = true then the whole expression is true no matter how many other parts are false, so if it is Saturday it doesn't matter what the time is because all day Saturday is out of hours. This differs from AND where all parts are required to be true to make the expression true. If A AND B AND C AND D = true. A B and C could be true but if D is false the whole expression is false.

ds AsDate Format('HHmm') Between('0000','0800')

ds uses the original value in the databox, the rest of this part of the expression converts the value to Hours and Minutes, it will then check if it's between Midnight and 8:00am. If it is it is out of hours.

ds AsDate Format('HHmm') Between('1800','2359')

Now a check is done to see if it's between 6:00pm and Midnight. If it is then it is out of hours.

ds AsDate Format ('dd/MM') InList("24/03,25/12,26/12",",")

Finally the original value in the databox is converted into the format Day/Month (dd/MM) and a list of Bank Holidays that has been defined are checked. If any of these are found then it is out of hours.


A simple message is setup to demonstrate this.