7 Replies Latest reply on Sep 30, 2013 1:04 PM by gkaiseril

    Midnight format in timesheet not working

    Talex904

      I am using Standard XI to create a timesheet that is filable. However, midnight is showing at 00:00 am not 12:00 am. Anything in that 12 am hour is 00.  Is there a script I can add to change it?

       

      I tried to download a free version of Pro to see if I could get something to work with that but it says my computer already has a program that is similar and won't download but I have no idea what that other program would be.

       

      I don't see anyway to add a document level script using Standard XI. What would I try next?

        • 1. Re: Midnight format in timesheet not working
          Test Screen Name Most Valuable Participant

          It's probably to avoid confusion, of which there is plenty on this subject.  http://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight

           

          The program that is similar to Pro is Acrobat Standard. You can't have both installed.

          • 2. Re: Midnight format in timesheet not working
            Talex904 Level 1

            So is there a way I can get the 00:00 am to show as 12:00 am using Standard XI?

            • 3. Re: Midnight format in timesheet not working
              try67 MVP & Adobe Community Professional

              What exactly is this a part of? You can write your own scripts to process time strings, but it's going to be a hell of a lot of work for this one small feature...

              • 4. Re: Midnight format in timesheet not working
                Talex904 Level 1

                Gilad D, I am trying to create a fillable PDF timesheet. But we have part-time people who start and/or stop at midnight. I was able to upgrade to Pro and put in a document-level script I found here on the forums to get 00:00 to show as 12:00 am however the formulas for my timesheet still give a negative number when someone starts or stops at midnight. I have been trying to add an if statement if the entered date is 12:00 am to add 12 hours but I haven't had any luck. Do you know what I could do to get it to work? Thanks!

                • 5. Re: Midnight format in timesheet not working
                  try67 MVP & Adobe Community Professional

                  Like I said, it's a lot of overhead for small a small feature... If you post your code I might be able to help you out with it.

                  • 6. Re: Midnight format in timesheet not working
                    Talex904 Level 1

                    As I have it scripted right now a start time of 12:00 am and an end time of 1:00 am equals -11.00 hours not 1.00 hour. What script would I have to add so the calculation is correct?

                     

                    Here is the script I have right now:

                    // start time

                    // Start time field name

                    var cStartName = "start1mon1";

                    // Start time format:

                    var cStartFormat = "HH:MM";

                    // end time

                    // end time field name

                    var cEndName = "end1mon1";

                    // End time format:

                    var cEndFormat = "HH:MM";

                    // some conversion functions

                    // function to convert time string to minutes

                    function Time2Num(cTime, cFormat) {

                    // convert time string to minutes

                    // convert time string to date object

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

                    // convert date object to number of milliseconds

                    var nTime = oDate.getTime();

                    // convert milliseconds to minutes and return value

                    return Math.round(nTime / (1000 * 60));

                    } // end Time2Num function

                    function Num2Time(nMinutes) {

                    // convert time string to Hours and Minute

                    // hours in nMinues

                    var nHrs = Math.floor(nMinutes / 60);

                    // remainder minutes from hours in nMinutes

                    var nMins = nMinutes / 60;

                    // return formatted time string

                    return nHrs, nMins;

                    } // end Num2Time

                    // end conversion functions

                    // perform the calculation using the fields:

                    // get the values of the fields

                    var cStartTime = this.getField(cStartName).value;

                    var cEndTime = this.getField(cEndName).value;

                    // clear the value

                    event.value = "";

                    // test for not null time strings

                    if(cStartTime != "" && cEndTime != "") {

                    // compute the time difference in minutes

                    nDiff = Time2Num(cEndTime, cEndFormat) - Time2Num(cStartTime, cStartFormat);

                    event.value = Num2Time(nDiff);

                    } //end not null values

                     

                    I have no prior knowledge of JavaScript, only what I have found here on the forums and a lot of luck. I would appreciate help on this problem. Thanks!

                    • 7. Re: Midnight format in timesheet not working
                      gkaiseril MVP & Adobe Community Professional

                      For date and time calculations there are 3 things to remember.

                       

                      Format! Format! Format!

                       

                      The script assuming the inputted data is formatted in the 24 hour format of 'HH:MM"

                       

                      Also check your conversion for the difference in minutes formatting function.

                       

                      function Num2Time(nMinutes) {

                      // convert time string to Hours and Minute

                      // hours in nMinues

                      var nHrs = Math.floor(nMinutes / 60);

                      // remainder minutes from hours in nMinutes

                      var nMins = nMinutes / 60;

                      // return formatted time string

                      return nHrs, nMins;

                      } // end Num2Time

                       

                      var nHrs = Math.floor(nMinutes / 60);

                      is almost the same as

                      var nMins = nMinutes / 60;

                       

                      To get the whole  minutes from the total minutes, use the modulos operator to get the remainder of the division

                       

                      var nMins = nMinutes % 60;

                       

                      When a numeric value  or character string is returned from a function it should be a single number or character string. If one must return multiple values then use an array.

                       

                      A custom validation script like:

                       

                      if(event.value.toSource().substr(18,1) == "a" || event.value.toSource().substr(18,1) == "p") {

                      event.rc = false;

                      app.alert("User 24 hour format");

                      }

                       

                      Could be used to test for the meridian text, not present in the 24 hour format.