Skip to main content
Known Participant
June 7, 2021
Answered

Remove NAN:NAN time between cells

  • June 7, 2021
  • 1 reply
  • 1170 views

Hi

I have a custom Java code to caluclate times between Take Off  & landing. Format in HH:MM, format out should be HH:MM.  However, the result is displaying NaN:NaN which is annoying until you enter times. Here is my code: Seems to work, just the NaN is annoying whilst the cells are blank. 

 

var hrsStart = parseInt(this.getField("Take Off Z1").value.split(":")[0]);
var minStart = parseInt(this.getField("Take Off Z1").value.split(":")[1]);
var hrsEnd = parseInt(this.getField("Landing Z1").value.split(":")[0]);
var minEnd = parseInt(this.getField("Landing Z1").value.split(":")[1]);
if (minStart > minEnd) {
var minRez = 60 + minEnd - minStart;
var hrsRez = hrsEnd - 1 - hrsStart;
} else {
var minRez = minEnd - minStart;
var hrsRez = hrsEnd - hrsStart;
}
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

This topic has been closed for replies.
Correct answer Nesa Nurani

Add condition to check if fields are empty:

if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

 

TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value  you can use: event.value

1 reply

Bernd Alheit
Community Expert
Community Expert
June 7, 2021

Perform the calculation only when the cells are not empty.

Known Participant
June 7, 2021

And how to initiate that? 

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
June 7, 2021

Add condition to check if fields are empty:

if(this.getField("Take Off Z1").valueAsString == "" || this.getField("Landing Z1").valueAsString == "")
this.getField("Flight Time1").value = "";
else
this.getField("Flight Time1").value = hrsRez + ":" + minRez;

 

TIP: if you use code in "Flight Time1" field, instead of: this.getField("Flight Time1").value  you can use: event.value