EL expression to determine the day and time in a branching condition
I would like to set an EL expression to determine the day of the week and time of day in a branching condition, but it does not work as expected.
How should I set up the expression?
What I want to do is to make the flow different during business hours (weekdays from 10:00 to 18:00) and after hours.
-
Official comment
Thank you for your question.
You are asking about EL expressions.For the day of the week and time at which the branching condition is determined (#now), the formula is as follows
Determining the day of the week:
#dateFormatter.format('u', #now) == '3'
1 = Monday, 2 = Tuesday...7 = Sunday, so the above formula determines if it is a Wednesday. To determine if it is a weekday, see if it equals 1-5, or not 6 or 7.
Determining the time of day
#now.after(#now.getFirstTimeInDate().addHours(10)) && #now.before(#now.getFirstTimeInDate().addHours(18))
In #now.getFirstTimeInDate().addHours(10), we determine if it is after 10:00 on that day with .after(). Similarly, #now.before(#now.getFirstTimeInDate().addHours(18)) determines if it is before 18:00 on that day.
Also, if you want to judge the value of a Datetime-type Data Item, for example, the following expression is used.
#q_date != null && #dateFormatter.format('u', #q_date) == '4'
#q_datetime != null && #q_datetime.after(#q_datetime.getFirstTimeInDate().addHours(10)) && #q_datetime.before(#q_datetime.getFirstTimeInDate().addHours(18))
#now is replaced by the data item #q_date / #q_datetime.
#q_date ! = null is a check to see if the value of the Data Item is non-empty.
However, since time is recorded in minutes in Datetime-type Data Items, only 10:01 to 17:59 is considered to be within the time period in the above expression. after() / before() will not include a value equal to the specified date and time (in this case, 00 minutes).
So, to include the 00 minute, the value should be evaluated at 1 minute before (.addMinutes(-1)) and 1 minute after (.addMinutes(1)).
#q_datetime != null && #q_datetime.after(#q_datetime.getFirstTimeInDate().addHours(10).addMinuites(-1)) && #q_datetime.before(#q_datetime.getFirstTimeInDate().addHours(18).addMinuites(1))
In this way, the 10:00 to 18:00 period will be correctly determined.
Comment actions
Please sign in to leave a comment.
Comments
1 comment