Help! Javascript calculated fields and coded buttons do not function in android Adobe Reader.

New Here ,
Mar 25, 2019

Copy link to clipboard

Copied

I have a job crew form that I have pretty much automated to save myself some time at the end of a job. And as a major part of this improvement my only option known to me to handle in/out time calculations using JavaScript to create a function [Time2Min] to convert the times to calculable values inside the function [TimeDiff] that performs the time difference operation. The code is below:

function Round(nValue, nPrecision) {

// round a number a given precision

return util.printf("%,101." + nPrecision + "f", nValue);

} // end round

function Time2Min(cFormat, sTime) {

sTime = sTime.toLowerCase();

// adjust for 12:MM am

if( (cFormat == "h:MM tt" || cFormat == "hh:MM tt") && ( (sTime.substr(0, 2) == "12" && sTime.substr(6,1) == 'a') || (sTime.substr(0, 2) == "12" && sTime.substr(5,1) == 'a') ) )

   sTime = "00" + sTime.substr(2, sTime.length - 2);

// convert a formatted time string to number of minutes since midnight

// get time object

var oTime = util.scand("mm/dd/yyyy " + cFormat, "01/01/1970 " + sTime);

// convert to milliseconds

var nTime = oTime.getTime();

// convert to milliseconds to minutes and return value

nTime = nTime / (1000 * 60);

// return round to whole minutes

return Number(Round(nTime, 0));

} // end Time2Min

function TimeDiff(cFormat, cTimeIn, cTimeOut) {

var nDiff = 0;

// get the value of the time in and out fields

   var sOut = this.getField(cTimeOut).value;

   var sIn = this.getField(cTimeIn).value;

   // compute if we have both values

   if(sOut != "" && sIn != "") {

      // convert time string to minutes and compute difference

  nDiff = Time2Min(cFormat, sOut) - Time2Min(cFormat, sIn);

      // convert to hours

      nDiff = nDiff / 60;

   }   // end if sOut & sIn

   // return rounded value 

   return Round(nDiff, 2);

   }

Is there any way to accomplish this with simple calculations? Please help.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

56

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Help! Javascript calculated fields and coded buttons do not function in android Adobe Reader.

New Here ,
Mar 25, 2019

Copy link to clipboard

Copied

I have a job crew form that I have pretty much automated to save myself some time at the end of a job. And as a major part of this improvement my only option known to me to handle in/out time calculations using JavaScript to create a function [Time2Min] to convert the times to calculable values inside the function [TimeDiff] that performs the time difference operation. The code is below:

function Round(nValue, nPrecision) {

// round a number a given precision

return util.printf("%,101." + nPrecision + "f", nValue);

} // end round

function Time2Min(cFormat, sTime) {

sTime = sTime.toLowerCase();

// adjust for 12:MM am

if( (cFormat == "h:MM tt" || cFormat == "hh:MM tt") && ( (sTime.substr(0, 2) == "12" && sTime.substr(6,1) == 'a') || (sTime.substr(0, 2) == "12" && sTime.substr(5,1) == 'a') ) )

   sTime = "00" + sTime.substr(2, sTime.length - 2);

// convert a formatted time string to number of minutes since midnight

// get time object

var oTime = util.scand("mm/dd/yyyy " + cFormat, "01/01/1970 " + sTime);

// convert to milliseconds

var nTime = oTime.getTime();

// convert to milliseconds to minutes and return value

nTime = nTime / (1000 * 60);

// return round to whole minutes

return Number(Round(nTime, 0));

} // end Time2Min

function TimeDiff(cFormat, cTimeIn, cTimeOut) {

var nDiff = 0;

// get the value of the time in and out fields

   var sOut = this.getField(cTimeOut).value;

   var sIn = this.getField(cTimeIn).value;

   // compute if we have both values

   if(sOut != "" && sIn != "") {

      // convert time string to minutes and compute difference

  nDiff = Time2Min(cFormat, sOut) - Time2Min(cFormat, sIn);

      // convert to hours

      nDiff = nDiff / 60;

   }   // end if sOut & sIn

   // return rounded value 

   return Round(nDiff, 2);

   }

Is there any way to accomplish this with simple calculations? Please help.

TOPICS
Acrobat SDK and JavaScript, Windows

Views

57

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 25, 2019 0
try67 LATEST
Most Valuable Participant ,
Mar 26, 2019

Copy link to clipboard

Copied

Why? What's wrong with what you have?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 26, 2019 0