Hi,
I am trying to subtract the two dates: End Date and Start date on the salary slip to get the number of days in the month (not working days) in a salary component formula.
I’m trying to figure out how dates work in a salary component formula as well. I’m going to did through the code to figure out how it works. What I did find so far, is where the formula is evaluated. Maybe this will help someone in the future.
Here’s some more details. Looks like the safe_eval function is being used, which whitelists specific global variables. This will at least help us know what functions are available to be called.
I wish I knew how the date was formatted. Seems to be a string, but I’m not sure how it’s formatted. If I know, I could probably convert it to a unix timestamp. Then it would be easy to work with in this very restricted safe_eval.
I think I figured it out though. The following two whitelists are what is available in the formula.
Notice, date and getdate are both available. This probably is flexible enough to work with the date object or convert it to a unix timestamp and do raw math.
I have confirmed that this works. If you’re trying to use dates with a salary component formula, use the getdate() function to convert the date into a python date object. Then you can go from there.
For example, if I want to get the month when an employee was hired, I would use the following.
getdate(date_of_joining).month
You can see all the available attributes on a python date object at the following docs.