Get End Time / Using Start Time and Hours Worked

Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

Hello World,

I'm still a Newbie to Acrobat and JavaScript.

I've been combing through the forums, Pubs and Manuals to create this code and cannot seem to get it to give me my answer.

I mean it doesn't display the result in my "StopTime" Text-field (Time - h:MM tt) and because I cannot figure out how to view my results line by line.

I don't know if it's because of prior code.

Could someone please advise what I'm doing wrong.

Here is the code I've created;

// get the start time and added time

var sStart = this.getField('StartTime').value;

var sWork = this.getField('Work').value;

var sTravel = this.getField('Travel').value;

//Convert Time to seconds

var vStart = Time2Num(sStart.FormattedValue, "h:MM tt");

var vWork = (sWork * 3600000);

var vTravel = (sTravel * 3600000);

If(HasValue('StartTime'))

{

    If(HasValue('Work') & HasValue('Travel'))

    {

          // Add Time

          var vTotal = vStart + vWork + vTravel;

    }

    ElseIf(HasValue('Work'))

    {

          // Add Time

          var vTotal = vStart + vWork;

    }

    Else

    {

        // Add Time

        var vTotal = vStart + vTravel;

    }

}

// Convert to time

var vStop = Num2Time(vTotal, "HH:MM");

// Display Time

event.value = ''

'StopTime'.value = util.printd("h:MM tt", vStop);

Any help would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript

Views

123

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

Get End Time / Using Start Time and Hours Worked

Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

Hello World,

I'm still a Newbie to Acrobat and JavaScript.

I've been combing through the forums, Pubs and Manuals to create this code and cannot seem to get it to give me my answer.

I mean it doesn't display the result in my "StopTime" Text-field (Time - h:MM tt) and because I cannot figure out how to view my results line by line.

I don't know if it's because of prior code.

Could someone please advise what I'm doing wrong.

Here is the code I've created;

// get the start time and added time

var sStart = this.getField('StartTime').value;

var sWork = this.getField('Work').value;

var sTravel = this.getField('Travel').value;

//Convert Time to seconds

var vStart = Time2Num(sStart.FormattedValue, "h:MM tt");

var vWork = (sWork * 3600000);

var vTravel = (sTravel * 3600000);

If(HasValue('StartTime'))

{

    If(HasValue('Work') & HasValue('Travel'))

    {

          // Add Time

          var vTotal = vStart + vWork + vTravel;

    }

    ElseIf(HasValue('Work'))

    {

          // Add Time

          var vTotal = vStart + vWork;

    }

    Else

    {

        // Add Time

        var vTotal = vStart + vTravel;

    }

}

// Convert to time

var vStop = Num2Time(vTotal, "HH:MM");

// Display Time

event.value = ''

'StopTime'.value = util.printd("h:MM tt", vStop);

Any help would be greatly appreciated.

TOPICS
Acrobat SDK and JavaScript

Views

124

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
Jun 22, 2019 0
Most Valuable Participant ,
Jun 22, 2019

Copy link to clipboard

Copied

If you copy and paste code from other scripts you have to make sure you copy all of the relevant parts. All of the functions you're using in your code (HasValue, Time2Num, Num2Time, etc.) are not defined in your code, so it can't work.

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...
Jun 22, 2019 0
Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

try67,

Thanks for your reply, I typed them in straight up.

As I said new to Acrobat Javascript, I assumed these were typical commands as they were in the manual.

So do I need to import something into my form for these functions to work like a macro of some kind.

Thanks for the quick reply,

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...
Jun 22, 2019 0
Most Valuable Participant ,
Jun 22, 2019

Copy link to clipboard

Copied

You need to find the definitions of those functions and include them in your code, yes.

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...
Jun 22, 2019 0
Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

I tracked the source of the Functions, they are Adobe but a different format of Adobe Javascript.

Why can't they make one common set of source commands for all their line of products.

Looks like I'm going to have to write new ones for HasValue, Time2Num, Num2Time in Adobe Acrobat Javascript.

If you happen to find someone else's version adapted to Acrobat Javascript, please let me know.

Hope this Newbie is up to it, thanks for your direction.

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...
Jun 22, 2019 0
Most Valuable Participant ,
Jun 22, 2019

Copy link to clipboard

Copied

I think all of this code comes from an LCD document, which is not the same as a regular PDF file, so you can't use it.

What is it exactly that you're trying to calculate?

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...
Jun 22, 2019 0
Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

I need to take the accumulated hours worked / traveled and add them to the start time of the service team member.
The resulting value being the finish time.

Calculated time.JPG

Adding a little error proofing of the daily log sheets.

Everything I found revolves around the date not the time.

Creation of a Function is a good idea for future edits and/or forms.

If you have a good starting place I'm all ears.

Thank You,

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...
Jun 22, 2019 0
Most Valuable Participant ,
Jun 22, 2019

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...
Jun 22, 2019 0
Community Beginner ,
Jun 22, 2019

Copy link to clipboard

Copied

Thanks,

Seen all of these and they are all time difference between, known times.

I'm trying to create the second time.

I'll use them as a base to develop the reverse of Thom Parker work.

Read quite a bit of his stuff looking for what I need.

Thank you for the insight.

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...
Jun 22, 2019 0
Most Valuable Participant ,
Jun 23, 2019

Copy link to clipboard

Copied

I could still develop it for you, if you wish. Contact me privately to discuss it further, please.

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...
Jun 23, 2019 0
Community Beginner ,
Jun 26, 2019

Copy link to clipboard

Copied

Found the answer,

Ended up being simpler then I thought, I didn't need to destruct the time strings.

Add the results and convert back using Functions.

Anyone that needs to add worked hours to a start time here is what I found and did.

Might be a little amateur, but I am new to Acrobat JavaScript (I'll add some ForLoops in later.

And it's good for 24hr logging.

DayShift.JPGNightShift.JPG

(function ()

    {

        // Get field values as numbers and calculate sum

        var vServiceRow1 = +getField("ServiceRow1").value;

        var vServiceRow2 = +getField("ServiceRow2").value;

        var vServiceRow3 = +getField("ServiceRow3").value;

        var vServiceRow4 = +getField("ServiceRow4").value;

        var vServiceRowSum = vServiceRow1 + vServiceRow2 + vServiceRow3 + vServiceRow4;

        var vWarrantyRow1 = +getField("WarrantyRow1").value;

        var vWarrantyRow2 = +getField("WarrantyRow2").value;

        var vWarrantyRow3 = +getField("WarrantyRow3").value;

        var vWarrantyRow4 = +getField("WarrantyRow4").value;

        var vWarrantyRowSum = vWarrantyRow1 + vWarrantyRow2 + vWarrantyRow3 + vWarrantyRow4;

        var vIdleRow1 = +getField("IdleRow1").value;

        var vIdleRow2 = +getField("IdleRow2").value;

        var vIdleRow3 = +getField("IdleRow3").value;

        var vIdleRow4 = +getField("IdleRow4").value;

        var vIdleRowSum = vIdleRow1 + vIdleRow2 + vIdleRow3 + vIdleRow4;

        var vBreak = +getField("Break").value;

        event.value = vServiceRowSum + vWarrantyRowSum + vIdleRowSum + vBreak;

        if (event.value == 0)

            {

                event.value = "";

            }

        else

            {

                event.value;

            }

    }

)();

event.value = ""; 

var vStartTime = this.getField("StartTime").valueAsString; 

if (vStartTime!="")

{

    var d = util.scand("mm/dd/yyyy HH:MM", "01/01/2017 " + vStartTime);

    var v = this.getField("Work").valueAsString;

    if (v!="")

    {

        var addTimeHours = Number(v);

        var msPerHour = 3600000;

        d.setTime(d.getTime() + (addTimeHours * msPerHour));

        event.value = util.printd("HH:MM", d);

    } 

}try67

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...
Jun 26, 2019 1