Skip to main content
Inspiring
August 11, 2020
Answered

Formatting using SFN

  • August 11, 2020
  • 3 replies
  • 2968 views

I'm trying to do this lesson i have from a book but it doesn't work.

I do everything as described in lesson but my result is 11.00 and not 11:00.

Can someone help?

This topic has been closed for replies.
Correct answer try67

Here  is the 2 pages with that lesson.


Surprisingly, it does work... I guess it picks up the Time format setting and converts the values to Date objects. The result is just a number, though. If you want to convert it to a "time" notation use this as the field's custom validation script:

event.value = Number(event.value).toFixed(2).replace(".", ":");

I added the call to the toFixed method because without it if you enter start time 11:30 and end time 14:45, for example, the result is 3.149999999 instead of 3.15. Also, if you only fill in one field it will show a result, which might not be desired.

3 replies

Thom Parker
Community Expert
Community Expert
August 11, 2020

I tried it on Acrobat X, XI, and DC. In all cases the time values were converted decimals and the calculations proceeded as normal decimal numbers. The time values were not handled properly.

You need to try values that cross the hour boundary.

 

Try 12:00 - 2:15

The time result is 9:45

And the decimal result is 9.85

I get the decimal result.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
August 11, 2020

Well, it uses 24-hour format and assumes that it's contained within the same day. If you go pass midnight then it doesn't work correctly, no, but neither would a script, unless it was built to do that.

Thom Parker
Community Expert
Community Expert
August 11, 2020

My calculation sample doesn't cross midnight. 

None of the samples shown in this thead, or the pages from the book show an example that crosses an hour boundary, not midnight, just an hour. 

 

Try 5:00 - 4:45

 

Tell me this calculation is working for you and send me an example, because I'm not seeing it.

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
August 11, 2020

Simplified Field Notation cannot be used to perform math on time values.  It does in fact convert the ":" to a decimal, but it does not handle hour minute conversions. And there are no formatting options for converting from a decimal back to time notation. 
If you want to really test this, then remove the formatting from the Total field so you can see the real value that is produced from the SFN calculation, then enter numbers that will cross an hour boundary.

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
August 11, 2020

What is the Format setting of the field?

Asim123Author
Inspiring
August 11, 2020

First two fields are formatted as time and 3rd field where result is shown is formatted as number with 2 decimals, thats what lesson says to do. 

try67
Community Expert
Community Expert
August 11, 2020

Then the screenshot they're using is not correct. A field set up as a Number field can't show the value "11:00".