Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
S_Strangfeld
Product and Topic Expert
Product and Topic Expert
With our latest release, b1702, the rules engine team of SAP SuccessFactors has delivered 5 new functions for time-related calculations.  So, what benefits will these rule functions have for you? Let’s have a look.

 

Imagine the following use case:

 

An employee would like to request a half-day off. Your company wants to make the life of its employees as easy as possible, and therefore uses the employee’s work schedule to set the default start and end time of their leave.

 

Sounds easy? Let’s have a look at the data and calculations you need for such a use case.

 

  1. You need the start and end time of the work schedule of the employee for that specific day (for example, 8:00 a.m. – 4:00 p.m.).

  2. You need the duration between start time and end time so you can calculate what “half day” means. (Imagine an employee who is working part time – half day leave would not automatically mean 4 hours).

  3. The system has to multiply the calculated working time for that particular day with a factor of 0.5 (half day) to get the working time for the day.

  4. The system has to deduct the calculated working time from the end time of the work schedule, or add the calculated working time to the start time of the work schedule of the employee for the specific day in order to get the end time of the half day leave.

  5. For each date and time, you have to ensure that the system delivers the data for the local time zone of the employee.


Still sounds easy?  It can be - if you use the new time functions which are available for SAP SuccessFactors Rule Engine as of our b1702 release.

 

  1. createDateTime

  2. calculateDurationBetweenTwoDateTimes

  3. addDurationToDateTime

  4. getLocalDateOfDateTime

  5. getLocalTimeOfDateTime


Now I’d like to introduce these time functions to you in a bit more detail:

 

  1. createDateTime is for fields of MDF data type DateTime, and returns a UTC timestamp. It uses the local date, local time, and the offset of the local time zone from UTC in hours. In our example, the work schedule information and leave request data contain local dates and times. In order to perform calculations, such as calculating durations between two time stamps, we need to transform them to UTC. This can be done with the new createDateTime function.

  2. calculateDurationBetweenTwoDateTimes calculates the time in seconds between two UTC timestamps. It’s important to note that if, for some reason, the first timestamp is after the second, the function will deliver a negative result. So, for example, the time between today 6 am UTC+1 (which is the default time zone for Germany) and yesterday 8 pm UTC+1 would be minus 36000 seconds (-10 hours). In our example, this function would be needed to calculate what the target working time is on the specific day the employee requested a half day leave for.

  3. addDurationToDateTime calculates an end UTC timestamp based on a start UTC timestamp and a duration in seconds.  For our use case, this function will be used to calculate the default value of the end time of the half day leave.

  4. getLocalTimeOfDateTime gets the local time of a UTC timestamp. The time depends on the time zone offset you specify. For example, for the UTC timestamp February 20th 2017 10 pm UTC+1, the function will deliver the local time February 21st, 2017, 5am for time zone Shanghai (which is UTC+8). In our example this function would be needed to provide the local default value of the end time of the half day leave request, based on the UTC timestamp which was calculated by the function addDurationToDateTime.

  5. getLocalDateOfDateTime delivers the local date of a UTC timestamp. Similar to the example above, this function would provide the local date February, 21st 2017 for Shanghai (UTC+8) out of the UTC timestamp 2017-02-20 10 pm UTC+1. This function is important to get the correct end date if, for example, the end date of the leave request is on another day (as can happen for shift workers).


All said and done it probably still looks a bit tricky, but with a well-defined rule you can most definitely implement the use case we were talking about. Try it out! 🙂



Screenshot of a part of a rule using the new functions

 

Of course, our use case is a simple one.  You’ll certainly have much more complicated work schedules like part time, 12 hour shifts, break times and so on that you have to take into account. There is a vast amount of conceivable use cases where you might need one or the other function or a combination thereof.  I’m sure you will find the right one and get your solution running. 😉

 

For some more information – please have a look into our Admin Guide.

 

Hope this helps!

 

Stay tuned… Best wishes, Sylvia