I have a timesheet that converts time entries to hours with ".00." It also rounds off to the quarter hour. Right now, it subtracts the "in" time from the "out" time and then converts it to hours and rounds them off. After working on it for some time, I need change the script to round off the time to the quarter hour BEFORE it does the arithmatic. Does anyone have a suggestion as to how I could do this with some reworking instead of starting over?
Here's the script:
// create JavaScript date time object for start time
var oStart = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeIn1").value);
// create JavaScript date time object for end time
var oEnd = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeOut1").value);
// compute difference in hours from the difference in hours
var DiffHours = (oEnd.valueOf() - oStart.valueOf()) / 1000 / 60 / 60;
if (oEnd.valueOf() < oStart.valueOf()) DiffHours = (DiffHours + 24);
var WholeHours = Math.floor(DiffHours);
// allow users to enter "12:00am" and still calculate correctly
var RegExp = /12/;
var RegExp2 = /am/;
var TOText = (this.getField("TimeOut1").value);
if(RegExp.test(TOText))
if(RegExp2.test(TOText))
WholeHours = (WholeHours + 12);
var TIText = (this.getField("TimeIn1").value);
if(RegExp.test(TIText))
if(RegExp2.test(TIText))
WholeHours = (WholeHours + 12);
// make total "0" if there is no time entered in either TimeIn or TimeOut
if(TIText == "")
(WholeHours = 0)
if(TOText == "")
(WholeHours = 0)
// calculate hours from time (:60) to (1.00) and round off to quarter hour
var DecHours = util.printf("%,302.0f",((DiffHours % 1) * 4).toFixed()) * 25;
var HourTotal = (WholeHours) + "." + (DecHours);
if (DecHours == 100) event.value = Math.ceil(HourTotal);
else event.value = (HourTotal)
Your custom calculation script then becomes:
event.value = DiffQtrHrs( TimeDiff('TimeIn1', 'TimeOut1') );
George Kaiser