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

PM too AM negative value

Svegetax
Registered: Oct 3 2009
Posts: 6
Answered

I've been fighting this for a day or so now and I can't seem to find an answer.
I made a time sheet for myself and coWorkers. The problem I have is any time I add a start time of PM and an end time after "AM" I get a negative value. Here in my code and is there any way to fix it?

var StartInterval = 0
if(HasValue(StartTime[0]) and HasValue(Until1[0])) then  
(Time2Num(Until1[0].formattedValue, "h:MM A") - Time2Num(StartTime[0].formattedValue, "h:MM A"))/(60*60*1000)
endif

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
You can use the Abs scripting method of FormCalc to convert negative values to positive.

Abs((Time2Num(Until1[0].formattedValue, "h:MM A") - Time2Num(StartTime[0].formattedValue, "h:MM A"))/(60*60*1000))

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

Svegetax
Registered: Oct 3 2009
Posts: 6
I tried that before and it just caused a new error in the total. Say you went from start :11:00 pm - Until 1:30 am, then the value comes up 21.5 hrs when it should be 2.5 hrs.
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Well, that's ok so far, cause your script only calculates the difference between the start an end time, doesn't know that you wish to calculate over two days.
Therefore you have to add a controll machnism and a second script, that calculates forward to the next day.

  1. //if start time is lower than end time.
  2. if (Time2Num(StartTime.formattedValue, "HH:MM:SS") < Time2Num(EndTime.formattedValue, "HH:MM:SS")) then
  3. Abs(Time2Num(StartTime.formattedValue, "HH:MM:SS") - Time2Num(EndTime.formattedValue, "HH:MM:SS")) /(60 * 60 * 1000)
  4. //If start time is higher than end time
  5. else
  6. 24 - Abs(Time2Num(EndTime.formattedValue, "HH:MM:SS") - Time2Num(StartTime.formattedValue, "HH:MM:SS")) /(60 * 60 * 1000)
  7. endif

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

Svegetax
Registered: Oct 3 2009
Posts: 6
OK!!
I got a variation of them working. Can't believe I forgot about >, and <. But here is what ended up working. Just in case others run into the same problem.FIX:
----- FormCalc) ------ var StartInterval = 0if(Time2Num(StartTime[0].formattedValue, "h:MM A")> Time2Num(Until1[0].formattedValue, "h:MM A"))then(Time2Num(Until1[0].formattedValue, "h:MM A")- Time2Num(StartTime[0].formattedValue, "h:MM A"))/(60*60*1000)+24else(Time2Num(Until1[0].formattedValue, "h:MM A") - Time2Num(StartTime[0].formattedValue, "h:MM A"))/(60*60*1000)endif