troubleshooting Question

Time2Num and Timesheets

Avatar of mjbdbase
mjbdbase asked on
JavaScriptAdobe Acrobat
2 Comments1 Solution1160 ViewsLast Modified:
Hello,
I have the following code for a simple timesheet.  I would like to add in a meal break field that can be taken off a total and am having trouble with the script.

The 4 fields in question are: rosstartmon (this is the shift start time), rosfinmon (this is the shift finish time), rosmealmon (the meal break) and the calculation field which is ResultHours.  All fields are time/date fields other than the ResultHours field which is a text field.

Here is the code I use to work out hours worked
 cqnursetimesheet.timesheet1.ResultHours::calculate - (FormCalc, client)

var TimeCount
var OneMinute = 1/60

if (rosstartmon ne null and rosfinmon ne null) then
	//if start time is lower than end time. 
	if (Time2Num(rosstartmon.formattedValue, "HH:MM") < Time2Num(rosfinmon.formattedValue, "HH:MM")) then
		TimeCount = Abs(Time2Num(rosstartmon.formattedValue, "HH:MM") - Time2Num(rosfinmon.formattedValue, "HH:MM")) /(60 * 60 * 1000)
	//If start time is higher than end time	
	else
 		TimeCount = 24 - Abs(Time2Num(rosfinmon.formattedValue, "HH:MM") - Time2Num(rosstartmon.formattedValue, "HH:MM")) /(60 * 60 * 1000) 
	endif

	var Minutes = Round(TimeCount / OneMinute)
	var Hours = 0
	
	for i = 0 upto 48 step 1 do
		if (Minutes >= 60) then 
			Minutes = Minutes - 60
			Hours = i + 1
		endif
	endfor
	$ = Concat(Hours, ":", Minutes, "")
endif

How do I add the meal break time into this code so that if the user enters (for example) 30 (for 30 minutes) it will take it off the total hours worked.
Thanks in advance
ASKER CERTIFIED SOLUTION
Richard Quadling
Senior Software Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros