Holiday Worked and Holiday Hours Scripting - TWP

This article covers:
In most cases, these scripts will be entered in the PayRateScript box. That is found in the Settings Menu > Processing Rules > Scripting category.

Change Regular Hours to Holiday Worked


Employees that work the holiday can have their pay type and pay rate changed with this script
Do a category change to a "Regular" punch in TimeWorks Plus and change it to "Holiday Worked" based on if that day is a holiday AND that employee actually worked that day:
 

if (reportingdate.isholiday and istimes and category = "Regular"){
    category = "Holiday Worked";}

 

The istimes condition insures that this script only runs if the employee used the clock. It will prevent the script from running on an hours entry like Vacation or Sick. We also added the condition to check that the category is "Regular", but if your client is changing categories to something other than regular, like for a shift differential, you may need to accommodate this as well in the script.

Changing the Pay Rate and the Category

To change the pay rate as well, do the same as in the previous example (change a category to "Holiday Worked") AND change the pay rate to the default pay rate times time and a half:
 

if (reportingdate.isholiday and istimes and category = "Regular"){
   category = "Holiday Worked";
   payrate = payrate * 1.5;}

Remove Holiday Hours when the Employee Works a Holiday

In the example above, the employee received both 8 hours of Holiday pay and the Holiday Worked rate. If your client wants to remove the Holiday hours in this situation, you can use this script, put in in the PayRate Script box also and positioned before the "Holiday Worked" script
 
if(reportingdate.isholiday and reportingdate.totalhours("Regular") > 0 and category = "Holiday")
     {
hours = 0;}

The script to remove Holiday hours should run before the script changing Regular to Holiday WOrked

Add Holiday Hours When the Employee Works a Holiday

Clients using the legacy HolidayRule will notice that employees who work a holiday will not receive holiday rules. To get around this, the best solution is to use the Holiday Configuration rule, which will pay holiday hours regardless of whether the employee works.

However, you can also use this script in conjunction with the HolidayRule to add holiday hours to the time card.

This script will go in the AddEntryScript rule box.
 
if (reportingdate.isholiday and reportingdate.totalhours("Regular") > 0){
   addentry("hours", 8, "Holiday");
}

The script uses the reportingdate.isholiday keyword to see if the date is a holiday. If yes, it also checks if there are "Regular" hours on the time card. If that is also true, then it uses the addentry function to create a new time card line with the Holiday hours.

More About addentry

addentry takes three arguments in the following order:
  • type - either hours or amount surrounded by quotes
  • numeric value - in this case, we are adding 8 hours
  • category - this would be the Punch Category of the entry, which must be contained in quotes and match a category in the Punch Categories rule
Prior to October of 2015, this was often done with a Split Post Reporting Date script. If you currently have a script like that in place on your account and would like to see details as to why it works, please see Add Holiday Hours - Split Post Reporting Date Method.

Remove Holiday Hours for Employees with Less Than 90 Days of Service

The following script can be used in TimeWorksPlus to limit Holiday hours to employees that have completed a probationary period, i.e. 90 days of service.

Before implementing this script, you'll need:
  • Designated holidays through the Holiday Configuration rule with one of the Pay Eligibility rules in place.

    The Holiday Configuration Rule should be set to pay Holiday hours for this script to work
  • Employees must have a Start Date in Employee Setup
The process used here is that employees will get Holiday hours based on the settings in the Holiday Configuration rule. Then the script checks to see if the employee has been with the company for less than 90 days. If that is true, the Holiday hours will be changed to 0.

The script has set the hours to 0 because this employee is still in the 90 day probationary period
This script will go in the PayRate Script box and is written to check for holiday hours on the time card. If it finds them, it checks to see if the employee has less than or equal to 90 days of service. If that is true, then the hours are set to 0.
 
if(reportingdate.isholiday and ishours and category = "Holiday" and employee.daysofservice <= 90){
     hours = 0;}

Can I Get Rid of the "Holiday" in the Category Column?

Your client might not like seeing a random "Holiday" entry on the time card with no hours tied to it. There is a way to also clear that out with one additional line added to our script:
if(reportingdate.isholiday and ishours and category = "Holiday" and employee.daysofservice <= 90){
     hours = 0;
     category = "Regular";}
By changing the category back to Regular, the time card will now display a null value in the category column.

Changing the Amount of Holiday Hours for Different Employees

This is a deprecated script that was used with the "HolidayRule" to adjust the amount of hours for different employees. For example, the HolidayRule could be used to give all employees 8 hours and then adjust that down to 4 hours for Part Time employees. However, with the Holiday Configuration rule, you can now do this without scripting.

The HolidayRule allows you to create a default amount of hours paid out automatically for employees that do not work holidays. However, it does not let you alter the amount of hours given to an employee based on different Employee Groups. The best solution for situations like that is to use the Holiday Configuration rule instead, but if your client is already using the HolidayRule and you want to keep it that way, follow these directions. 

The HolidayRule (our legacy Holiday Rule) cannot pay different hours to different employees
This script requires an identifier in Employee Setup so you can select the employees affected by this script. In our example we set the default to 8 hours in the Holiday Rule and, based on an identifier in Home 3 of Employee Setup, make adjustments to the 8 hours based on whether the employee is Part Time or within a probationary period.

This script will use the Home 3 field to determine Part Time employees

In the script below, we check if the hours meet the following criteria:
  1. If the day is a holiday 
  2. There is an hours only punch present that is equal to 8 hours
  3. Is the category for that punch "Holiday"
  4. If the employee with this punch has "PT" in Employee Setup Home 3. If so adjust the hours from 8 to 6 hours

if(reportingdate.isholiday and ishours and hours = 8 and category = "Holiday"){
    if(employee.home3 ="PT"){
        hours = 6;}
}


The next script will do everything the first script did, but also zero out the hours for employees with less than 90 days of service.
 

if(reportingdate.isholiday and ishours and hours = 8 and category = "Holiday"){
    if(employee.home3 ="PT"){
        hours = 6;}
    if(employee.daysofservice <= 90){
        hours = 0;}

}


Because of the way the previous script is structured, it will also apply to PT employees who have less than 90 days of service. First the script will change their hours to 6, but then, after it checks their days of service and sees they are ineligible for Holiday hours, it will zero out the hours.

Exclude Weekends from AutoHoliday Hours

The Holiday Rule will apply hours to any company recognized holiday. However, if a holiday falls on a weekend and the client does not want to pay holiday hours in that circumstance to remove the hours from the time card.

In this example script, we are operating under the following situation:
  • The account has holidays designated through one of the Holiday Rules (i.e. USHolidays, Custom Holidays, etc.)
  • The client has the Holiday Rule setup to add 8 hours to the time card for any employee that does not work the holiday
  • The client does not pay holiday hours if the holiday falls on a Saturday or Sunday
  • If the script recognizes that there is an 8 hour entry on a holiday, the hours will be changed to 0
if(reportingdate.isholiday and "SU" contains weekday (punchdate)){
     if(ishours and hours = 8 and category = "Holiday"){
          category = "Regular";
          hours = 0;
     }
}
 

Scripting Based on Day Before/After Holiday

Note this only works in TimeWorksPlus. What the script does is confirms that the day on which it is running is the day before the holiday or the day after. If it is determined to be true, we can then script additional commands based on its findings.

To do something on the day after a holiday:


if(reportingdate.isholiday(reportingdate.date - 1)){...}
 

reportingdate.isholiday is checking if the day prior to the selected day on the time card was a holiday. It does this by running the isholiday logic on the reportingdate.date minus one day. If it is, then the script will execute any following commands between the braces, {}..

To do something on the day before a holiday:


if(reportingdate.isholiday(reportingdate.date + 1)){...}

Did you find this article helpful?