Check if within Working hours

From Keyfax Wiki
Jump to: navigation, search

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.

Outofhours.png

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.

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.

Outofhours3.png

Outofhours2.png