The date and time fields are string fields and not numeric fields because they contain the colon character and the optional meridian value. The date and time fields also do not add decimal numbers, they tend to be circular or get to a certain value and cycle back to 1. So one can not just add the field values together. One needs to transform the date or time string into a numeric value that represents a measure of time from a given point in time. Both Acrobat and LiveCycle Designer have a given base date, the Epoch date, form which the time interval is measured in milliseconds or days. Both products also provide some functions or methods to convert the date or time into this numeric value. Once one has the appropriate numeric value any number of time items or calculations can be performed.
First one needs to convert the time strings into a numeric value and the FormCalc function to provide this value is the "Time2Num()" function. This function returns the number of milliseconds, 1/1000 of a second, from the epoch date or start of the day if only the time string is provided.
So one can get the StartTime, formatted as "h:MM A", in milliseconds with:
Time2Num(StartTime.formattedValue, "h:MM A")
and the LunchStart time with:
Time2Num(LunchStart.formattedValue, "h:MM A")
And the difference for this intervals then
Time2Num(LunchStart.formattedValue, "h:MM A") - Time2Num(StartTime.formattedValue, "h:MM A")
And a similar coding will provide the time after lunch.
Adding some code to accumulate these periods and only compute an interval when the necessary variables are available one could have to get the time interval in milliseconds and then only needs to convert the milliseconds into hours by dividing by 3,600,000 milliseconds in one hour.
// compute time before lunch in milliseconds
var StartInterval = 0
if(HasValue(LunchStart) and HasValue(StartTime)) then
StartInterval = Time2Num(LunchStart.formattedValue, "h:MM A") - Time2Num(StartTime.formattedValue, "h:MM A")
endif
// compute time after lunch in milliseconds
var EndInterval = 0
if(HasValue(LunchEnd) and HasValue(EndTime)) then
EndInterval = Time2Num(EndTime.formattedValue, "h:MM A") - Time2Num(LunchEnd.formattedValue, "h:MM A")
endif
// compute total time in hours from the millisecond value
Sum(StartInterval, EndInterval) / 3600000