2 Replies Latest reply on Oct 7, 2010 11:59 PM by George_Johnson

    PDF textfield Calculations!

    sthompson86

      Adobe Scripters,

       

      Looking for some help with a few of my scritps.

       

      Basically i have borrowed a script that will allow me to help my workplace calculate a timeframe.

       

      I have 5 timeframes that are used from the current time.

       

      • +4 Hours of current time.
      • +24 Hours of current time.
      • +48 Hours of current time.
      • +72 Hours of current time.
      • +20 Working Days of current time.

       

      Please see my current pdf.

       

      untitled22.JPG

       

      The current script for the +24 hour timeframe that is working fine from calcualtion field within the textfield properties.
       
      event.value = "";

      // Get the string date from the current date field
      var strDate = this.getField("DateCurrent").value;

      // We already know the exact format since we put it there, makes it easy to scan
      if(!/^\s*$/.test(strDate))
      {
        var oDate = util.scand("mm/dd/yy,  ddd, hh:MM:ss ",strDate);
        if(oDate)
        {
          // Calculate 5 years in milliseconds
          var fiveDays = 1 * 24 * 60 * 60 * 1000;
          // Create a new date object so we can format it
          oDate = new Date(fiveDays + oDate.getTime());
          event.value = util.printd("dddd dd-mmm-yyyy - HH:MM:ss", oDate);
        }
      }

      but here is my delema...

       

      4h timeframe script is ok because contractors are required to have work done 7 days/week

       

      24h timeframe script is ok because contractors are required to have work done 7 days/week

       

      42h timeframe script needs to exclude sundays into the calculations and if so must have +24 added if sunday falls within the timeframe. If an order was placed on friday 1pm the current script would advise the order is due on sunday 1pm... i need a script that will push the date forward to monday 1pm.

       

      72h timeframe script needs to exclude sundays into the calculations and if so must have +24 added if sunday falls within the timeframe. If an order was placed on friday 1pm the current script would advise the order is due on monday 1pm... i need a script that will push the date forward to tuesday ect 1pm.

       

      RSW is the bigger problem... rsw is a 20 working day timeframe that needs to exclude both saturday and sunday, at the moment im using 28 days in the script but if and order is raised on a saturday or sunday it will end on a sunday or saturday and will require it to be pushed forward to the following monday.

       

      If anyone can help me it would be much appriciated.

       

      Please send me and email and i can send you my PDF if you believe you can help me out.

       

      Steven Thompson

        • 1. Re: PDF textfield Calculations!
          sthompson86 Level 1

          Please email me if you require me to send the pdf orginal if this would make it easier.

           

          steven.thompson@housing.nsw.gov.au

           

          Thanks in advance.

          • 2. Re: PDF textfield Calculations!
            George_Johnson MVP & Adobe Community Professional

            The format of the current date field doesn't match the format your code is using in the scand call, so I'll assume the screen shot is correct. Here's some code you can use as the custom Calculate script for the RSW field and modify to suit the other fields. In particular, you'll have to determine the correct days to add based on the current day of the week, and modify the days_to_add array accordingly.

             

            // Custom Calculate script for RSW field

            (function () {

             

                // Get the date string from the current date field
                var strDate = getField("DateCurrent").value;

             

                // Array of days to add based on current day of the week
                var days_to_add = [26, 25, 27, 27, 27, 27, 27];

             

                if (strDate) {

             

                    // Convert current date string to Date object
                    var oDate = util.scand("dddd dd-mmm-yyyy - HH:MM:ss", strDate);

             

                    // Get day of the week
                    var day = oDate.getDay();

             

                    // Add appropriate number of days
                    oDate.setDate(oDate.getDate() + days_to_add[day]);

             

                    // Set this field to date string of future date
                    event.value = util.printd("dddd dd-mmm-yyyy - HH:MM:ss", oDate);

             

                } else {

             

                    event.value = "";
                }

             

            })();

             

             

            Note that I could have gotten the number of days to add wrong. I'm assuming the current day counts as a working day.