If then else not working in PDF
Long story short I figured out a simple way to calculate time in PDF using the export value field in the drop down selection list based on 24 hours. I broke the drop downs into three groups Hours (1-12 exports 1-12), Mins (in 15 min chunks based on 1 hr numerical value in export 15=0.25) and the AM/PM (AM 0 or adds 12 hours for PM) for both start and end times along with a break time (1-2 hours in 15 min chunks). The formula works fine for getting the fields, adding them up, and the subtracting the to the the total time worked, even breaking over the midnight barrier (which I had used in another version where the drop down menu contained all 24 hours in 15 min chunks but for this pdf it was too clunky to use the drop down that large). The trouble I noticed is when you use any 12 PM combo with AM time (it creates a midnight crossover because of the math). I then tried to add an else to the if statement doing the midnight crossover and keep getting the error invalid assignment left-hand side after the else if statement. Here's the code I'm trying:
//Get Time Values
var StartTimeHour = this.getField("STH1").value;
var StartTimeMin = this.getField("STM1").value;
var StartTimeAP = this.getField("STAP1").value;
var EndTimeHour = this.getField("ETH1").value;
var EndTimeMin = this.getField("ETM1").value;
var EndTimeAP = this.getField("ETAP1").value;
var BreakTime = this.getField("Break1").value;
//Combine Time Values
var StartTime = (StartTimeHour + StartTimeMin + StartTimeAP);
var EndTime = (EndTimeHour + EndTimeMin + EndTimeAP);
//Calculate Time
var TimeWorked = ((EndTime - StartTime) - BreakTime);
//Test for Midnight Crossover
if(TimeWorked < 0)
{// Shift 24 hours
TimeWorked += 24;
}else if(TimeWorked >0 && EndTimeAP = 12)
{// Remove 12 hours
TimeWork -= 12;
}
}
//Print Results
event.value = TimeWorked;
I also tried to put in a separate if statement before the Combine Time Values and got the same error here's that code:
//Get Time Values
var StartTimeHour = this.getField("STH1").value;
var StartTimeMin = this.getField("STM1").value;
var StartTimeAP = this.getField("STAP1").value;
var EndTimeHour = this.getField("ETH1").value;
var EndTimeMin = this.getField("ETM1").value;
var EndTimeAP = this.getField("ETAP1").value;
var BreakTime = this.getField("Break1").value;
//Test for 12 pm
if(EndTimeHour = 12 && EndTimeAP = 12)
{//Remove 12 hours
EndTimeAP -=12;
}
//Combine Time Values
var StartTime = (StartTimeHour + StartTimeMin + StartTimeAP);
var EndTime = (EndTimeHour + EndTimeMin + EndTimeAP);
//Calculate Time
var TimeWorked = ((EndTime - StartTime) - BreakTime);
//Test for Midnight Crossover
if(TimeWorked < 0)
{// Shift 24 hours
TimeWorked += 24;
}
//Print Results
event.value = TimeWorked;
This is the code that always works but has the 12am/12pm issue I was trying to solve:
//Get Time Values
var StartTimeHour = this.getField("STH1").value;
var StartTimeMin = this.getField("STM1").value;
var StartTimeAP = this.getField("STAP1").value;
var EndTimeHour = this.getField("ETH1").value;
var EndTimeMin = this.getField("ETM1").value;
var EndTimeAP = this.getField("ETAP1").value;
var BreakTime = this.getField("Break1").value;
//Combine Time Values
var StartTime = (StartTimeHour + StartTimeMin + StartTimeAP);
var EndTime = (EndTimeHour + EndTimeMin + EndTimeAP);
//Calculate Time
var TimeWorked = ((EndTime - StartTime) - BreakTime);
//Test for Midnight Crossover
if(TimeWorked < 0)
{// Shift 24 hours
TimeWorked += 24;
}
//Print Results
event.value = TimeWorked;
I cannot see how the Midnight crossover works here, but when I do something similar right after getting the values I don't understand why that does not work, but the Midnight cross over does. If someone could show me whats wrong that would be great. I tried a non Java fix, by making the ETM1's 12 export out 0, but then this causes a math issue for the midnight crossover.
Thanks
