These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

time to hours conversion script

sjsmith
Registered: Sep 2 2008
Posts: 28
Answered

I'm working on a timesheet which requires that a user's time entry be converted to hours rounded off to the nearest ".25." I have two problems with the script below.

1. If a user enters their time, say 9:03am to 5:00pm, it comes back with "7.10" hours instead of "8.00."

2. If a user enters time that crosses over the date, say 8:00pm to 4:00am, it comes back with "-16.00" instead of "8.00."

var oStart = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeIn1").value);

var oEnd = util.scand("yyyy/mm/dd hh:mm", util.printd("yyyy/mm/dd ", new Date()) + this.getField("TimeOut1").value);

var DiffHours = (oEnd.valueOf() - oStart.valueOf()) / 1000 / 60 / 60;
event.value = Math.floor(DiffHours)+ "." + util.printf("%,302.0f",((DiffHours % 1) * 4).toFixed()) * 25

Any help would be much appreciated.

My Product Information:
Acrobat Pro 7.0.7, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4308
Since it appears you are using Acro Forms and not LiveCycle Designer,

> 1. If a user enters their time, say 9:03am to 5:00pm, it comes back with "7.10" hours instead of "8.00."Use the "Math.ceil()" method to round up to the next higher whole number.

> 2. If a user enters time that crosses over the date, say 8:00pm to 4:00am, it comes back with "-16.00" instead of "8.00."You will need to include a date field for the start and end times and not force the current date into the date time object for the start and end times. Or add some code to test if the start time is later than the end time and "assume" the start date was the day before the end date. "new Date()" returns the current date.

George Kaiser

sjsmith
Registered: Sep 2 2008
Posts: 28
Thank you very much. My problems are solved and the form is running smoothly.