Rounding a time calculation

New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

I'm trying to make my service ticket that i created round our times in and out to the nearest .25 of an hour.

Here is what i have for the time calculation-

// determine the current row number

var ourName = event.target.name;

var matches = ourName.match(/.*(\d+)$/);

var rowNum = matches[1];

handleRow("h:MM tt", "StartTime", "StopTime", "BreakTime", "Overtime", rowNum);

But as of now it calculates just 1.34, 2.89. I want it to round down and up. So if its .12 hours round down to .00 and it if its .38 to round to .5 and so on.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You've either added or removed a curly bracket that you shouldn't have...


Here's the edited file with working code: https://drive.google.com/open?id=188qGrMtVRjsif6MHP4euSaFDcrC0tRsB

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

172

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

Rounding a time calculation

New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

I'm trying to make my service ticket that i created round our times in and out to the nearest .25 of an hour.

Here is what i have for the time calculation-

// determine the current row number

var ourName = event.target.name;

var matches = ourName.match(/.*(\d+)$/);

var rowNum = matches[1];

handleRow("h:MM tt", "StartTime", "StopTime", "BreakTime", "Overtime", rowNum);

But as of now it calculates just 1.34, 2.89. I want it to round down and up. So if its .12 hours round down to .00 and it if its .38 to round to .5 and so on.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You've either added or removed a curly bracket that you shouldn't have...


Here's the edited file with working code: https://drive.google.com/open?id=188qGrMtVRjsif6MHP4euSaFDcrC0tRsB

TOPICS
Acrobat SDK and JavaScript, Macintosh, Windows

Views

173

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
Aug 27, 2018 0
Most Valuable Participant ,
Aug 27, 2018

Copy link to clipboard

Copied

Post the code of the handleRow function.

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...
Aug 27, 2018 0
Adobe Community Professional ,
Aug 27, 2018

Copy link to clipboard

Copied

What is handleRow?

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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

Im not sure what the handlerow is... my former coworker did all this stuff prior and he just stole the code from somewhere on the internet.

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...
Aug 27, 2018 0
Most Valuable Participant ,
Aug 27, 2018

Copy link to clipboard

Copied

We need the full code to be able to help you out. It might be easier if you could share the actual file with us (via Dropbox, Google Drive, Adobe Send & Track, etc.).

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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

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...
Aug 27, 2018 0
Most Valuable Participant ,
Aug 27, 2018

Copy link to clipboard

Copied

OK, the code is located under a doc-level script. Go to Tools - JavaScript - Document JavaScripts and you'll find it.

To achieve what you asked for change this part of it:

function handleRow(cFormat, cInBase, cOutBase, cBreakTimeBase, cOverTimeBase, rowNum)  {

    var timeDiff = TimeDiff(cFormat, cInBase + "." + rowNum, cOutBase + "." + rowNum, cBreakTimeBase + "." + rowNum);

    if (timeDiff > 8) {

        this.getField(cOverTimeBase + "." + rowNum).value = timeDiff - 8;

        timeDiff = 8;

    }

        else

        {

                this.getField(cOverTimeBase + "." + rowNum).value = "";

        }

    event.value = timeDiff;

}

To this:

function handleRow(cFormat, cInBase, cOutBase, cBreakTimeBase, cOverTimeBase, rowNum)  {

    var timeDiff = roundToNearestQuarter(TimeDiff(cFormat, cInBase + "." + rowNum, cOutBase + "." + rowNum, cBreakTimeBase + "." + rowNum));

    if (timeDiff > 8) {

        this.getField(cOverTimeBase + "." + rowNum).value = timeDiff - 8;

        timeDiff = 8;

    }

        else

        {

                this.getField(cOverTimeBase + "." + rowNum).value = "";

        }

    event.value = timeDiff;

}

function roundToNearestQuarter(v) {

    return (Math.round(v * 4) / 4).toFixed(2);

}

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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

Im getting a

SyntaxError: syntax error

57: at line 58

This is what it highlights

nDiff = nDiff + 24;

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...
Aug 27, 2018 0
Most Valuable Participant ,
Aug 27, 2018

Copy link to clipboard

Copied

That means you edited something you shouldn't 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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

the chunk of code I'm replacing is the first chunk there correct?

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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

now im gettin a SyntaxError: Missing } in compound statement 56: at line 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
Reply
Loading...
Aug 27, 2018 0
Most Valuable Participant ,
Aug 27, 2018

Copy link to clipboard

Copied

You've either added or removed a curly bracket that you shouldn't have...


Here's the edited file with working code: https://drive.google.com/open?id=188qGrMtVRjsif6MHP4euSaFDcrC0tRsB

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...
Aug 27, 2018 0
New Here ,
Aug 27, 2018

Copy link to clipboard

Copied

Thanks much!

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...
Aug 27, 2018 0