How to determine if someone is working
We are creating a temporary variable called Working, one value for each calculation date (i.e., #DATE), where 1 indicates you are working and a 0 indicates you are not working.
In general, you are considered to be working (e.g., accruing service/salary) if you are in a start event (e.g., EventHistory #IN (10,11,12) or #DATE >= the start event date) or it's the first day of the stop event (e.g., #DATE = the stop event date). For example, if you work the full year, but terminate on 12/31/2020, do you earn a full year of service/salary? In most cases you do, so that's why we are using #DATE (the stop event date) in some of the expressions below. That's also why we are using (#DATE <= StopEventDates) rather than (#DATE < StopEventDates).
For these examples, we are assuming:
If we aren't using an event history, just the date of hire (e.g., DateOfHire) and decrement date (e.g., #DODEC), then expression is simple:
Working:= (#DATE >= DateOfHire) #AND (#DATE <= #DODEC) &
When we are using events, we have many different ways of determining if someone is working:
Working:= (EventHistory #IN (10,11,12)) #OR (#DATE = #START EventHistory) &
; (1) Works in any expression supporting #START.
; (2) Assumes the decrement event is in EventHistory. If it's not, add #OR (#DATE = #DODEC)
; (3) Doesn't require StartEventDates and StopEventDates.
Working:= (EventHistory #IN (10,11,12)) #OR (#DATE = StopEventDates) &
; Assumes the decrement event is in EventHistory. If it's not, add #OR (#DATE = #DODEC)
Working:= (#DATE >= StartEventDates) #AND (#DATE <= StopEventDates) &
; assumes the decrement date is in StopEventDates (at the last start event date)
Working:= (#DATE <= #DODEC) #AND {IsStart #OR [(#NOT IsStart) #AND (1 = {'P' #GETASOF IsStart}) ]] &
; ... #AND {in a start event #OR it's the first day of a stop event}
; ... it's the first day of a stop event: you are in a stop event, but on the immediately
; preceding date you were in a start event
; This works because all the start and stop event dates (and the day before each date) were added to
; the set of calculation dates. So, on any stop date in #DATE, IsStart contains a zero and on the
; day before the stop date, IsStart contains a 1 (because you were in a start event).