Home      Ask a Question      My Stuff      Help   
  
TimeWorksPlus - Round Hours Instead of Punches
TimeWorksPlus scripting provides additional options for rounding hours. Instead of rounding individual in and out punches, you can round the hours reported on the time card. So instead of rounding 9:08am to 9:15am, you can round to amount of hours to the nearest quarter hour so that, regardless of the punch times, 4 hours and 20 minutes rounds to 4 hours and 15 minutes.

This script will round the total hours in the week to the nearest quarter hour. It should be put in the PayRate Script box. It will look at all hours on the time card (regular, overtime, vacation, etc.) but it will only change the regular hours.

$adj = 0;
$hrs = reportingdate.weekhours;
$per = 25;

if(istimes and category = "Regular"){
if(($hrs * 100) % $per > 0){
$adj = (round(($hrs * 100)/ $per,0) * $per)/100;

if($hrs - $adj > 0 ){
hours = hours - ($hrs - $adj);
addalert("Hours reduced by " + ($hrs - $adj) + " hours.");
} else {
hours = hours +($adj -$hrs );
if($adj - $hrs > 0){
addalert("Hours increased by " + ($adj - $hrs) + " hours.");}
}
}
}




This script changes the hours reported on the first Regular punchset of the week so that the week’s total hours are rounded to the nearest quarter of the hour. So, in this time card, the hours reported on the Monday 8am to 12:09pm punchset have been changed from 4.15 hours to 4.12 hours for the purpose of rounding the total hours in the week to 15.25. It also includes an addalert to let a viewer of the time card see that an adjustment has been made to their hours.
________________________________________________________________________________

VARIATIONS

By modifying certain values in this script, you can use it in different rounding scenarios.

ROUND THE HOURS IN THE DAY TO THE NEAREST QUARTER HOUR
Our previous script made it so that the totaled hours for the week always rounded to the nearest 15 minutes. However, with a change to one line, we can have this script round the hours in a day to the nearest quarter hour.

$hrs = reportingdate.totalhours;

Would replace the second line of our script above. Now, instead of looking at the value of reportingdate.weekhours, the script looks at the value of reportingdate.totalhours, which returns the hours in a single day. The end result will be a daily total that is always reported to the nearest quarter hour.

ROUND EACH PUNCHSET TO THE NEAREST QUARTER HOUR
Just as we can make the weekly and daily total appear in quarter hour increments, we can modify the above script so that each and every entry on the time card is reported in quarter hour increments. This would be done by once again modifying the second line of the script.
$hrs = hours;
The ‘hours’ keyword returns the hours of each individual punchset.

ROUND DAY'S HOURS TO THE NEAREST TENTH OF AN HOUR
Suppose your client wants all times, each day, in 6 minute increments (1/10th of an hour). That could be done by choosing a different value for the variable $per.

Instead of: $per = 25;
use: $per = 10;

and then setting $hrs = reportingdate.totalhours; so that the script looks at the total hours in the day.

IMPORTANT: Can I use Something Other Than Quarter or Tenth of an Hour?
Not necessarily. This script will only work with increments that are an even percentage of 60 minutes, i.e. 30 minutes, 15 minutes and 6 minutes. 20 minutes and 10 minutes will not work. This is because 20 minutes is 33.333…% of 60 and 10 minutes is 16.6666…% of 60. But, because 30 minutes is 50% of 60, you could use 50 as your $per value to round to the nearest half hour.
ID
1787
Category
>Support
  Scripting
Date Created
2/3/2016 1:00:54 PM
Date Updated
2/18/2016 2:09:08 PM
Back to Search Results