6 Replies Latest reply on Feb 13, 2012 7:37 AM by Srini Dhulipalla

    Date bug?

    Jerry62712 Level 1

      I have a PDF that seems to have a date problem.  I have a date picker or the user can enter the date manually.  I take the date and use it to populate column headers for a week.  If you enter 1/1/12 then Monday becomes 1/1, Tuesday 1/2, etc.  This works if you use the calendar.  This works if you use mm/dd/yy.  It doesn't work if you enter mm/dd/yyyy.  I can't imagine why a full year won't work when a 'yy' format will work.

       

      Here is the code from my PDF:

      form1.TimeEntry.EmployeeTime.OperatingDate.MondayDate.rawValue = $.rawValue;

      form1.TimeEntry.EmployeeTime.OperatingDate.TuesdayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+1,"YYYY-MM-DD");

      form1.TimeEntry.EmployeeTime.OperatingDate.WednesdayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+2,"YYYY-MM-DD");

      form1.TimeEntry.EmployeeTime.OperatingDate.ThursdayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+3,"YYYY-MM-DD");

      form1.TimeEntry.EmployeeTime.OperatingDate.FridayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+4,"YYYY-MM-DD");

      form1.TimeEntry.EmployeeTime.OperatingDate.SaturdayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+5,"YYYY-MM-DD");

      form1.TimeEntry.EmployeeTime.OperatingDate.SundayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+6,"YYYY-MM-DD");

      form1.TimeEntry.CATSSundayDate.rawValue  = Num2Date(Date2Num($.rawValue, "YYYY-MM-DD")+6,"YYYY-MM-DD");

       

      Adobe support didn't have any answer other than to block manual entry.  I'm wondering if this is a bug.

        • 1. Re: Date bug?
          Jerry62712 Level 1

          I tried reworking it, but it still doesn't work.  This code:

           

          var startAsNumber = Date2Num($.rawValue, "MM/DD/YY");

          xfa.host.messageBox($.rawValue,"Raw value");

          xfa.host.messageBox($.formattedValue,"Form value");

           

          var startAsNumber2 = Date2Num($.formattedValue);

          xfa.host.messageBox(startAsNumber2, "num formatted");

           

          form1.TimeEntry.EmployeeTime.OperatingDate.MondayDate.rawValue =       Num2Date(startAsNumber2+0,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.TuesdayDate.rawValue  = Num2Date(startAsNumber2+1,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.WednesdayDate.rawValue = Num2Date(startAsNumber2+2,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.ThursdayDate.rawValue = Num2Date(startAsNumber2+3,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.FridayDate.rawValue =       Num2Date(startAsNumber2+4,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.SaturdayDate.rawValue = Num2Date(startAsNumber2+5,"YYYY-MM-DD");

          form1.TimeEntry.EmployeeTime.OperatingDate.SundayDate.rawValue =       Num2Date(startAsNumber2+6,"YYYY-MM-DD");

          form1.TimeEntry.CATSSundayDate.rawValue =                         Num2Date(startAsNumber2+6,"YYYY-MM-DD");

           

          had message boxes with:

          2012-001-04

          Jan 4, 2012

          40911

           

          And the input field displays "Jan 4, 2012".  It produced the expected output using 1/4/12 as the input. 

          Change that to 1/4/2012 and you get:

          1/4/2012

          1/4/2012

          0

          With the input field display of "1/4/2012" you get completely different results in all display boxes.

           

          Totally different output depending on if you include the century on the date or not.  And the final "0" makes the dates start from 1/1 instead of 1/4.  The only pattern is "Data" and it is date{YYYY-MM-DD}.

           

          While I'm a relatively newbie in LiveCycle, I've been a programmer for many years and am pretty sure this isn't right.

          • 2. Re: Date bug?
            Srini Dhulipalla Level 5

            Jerry,

                 Your issue is with the pattern. If you do not set an Edit pattern to the Date field, the default pattern will be m/d/yy.

                

                 If you allow user to enter the date manually and would like to handle multiple combinations of date entries (for example: m/d/yy, mm/dd/yy, mm/dd/yyyy) then you need to manually write script to handle such situations.

             

                 The easier way is to set an Edit pattern in the field properties and check the input to match to that pattern. If the user enters a different pattern value, then display a message and ask for the correct input format.

             

                 You can write date validation script in Java Script and display the dates for Headers.

             

            Thanks

            Srini

            • 3. Re: Date bug?
              Jerry62712 Level 1

              Srini,

               

               

               

              I have two issues.  One is why LiveCycle treats 1/1/12 as one date with one behavior and 1/1/2012 as a completely different date with different behaviors.

               

               

               

              The second is when I use this as the edit and validation pattern, date{M/D/YY}, you are allowed to enter 1/2/2012 which breaks the form as the math for 1/2/2012 is completely different than the math for 1/2/12.

               

               

               

              I was hoping to extract the various pieces of the date to get around this bug, but I’m not sophisticated enough to do it.  I would have then rebuilt the date after adding 1, 2, 3 … to the day part allowing LiveCycle to adjust for months, years, leapdays, etc.

               

               

               

              Are you the Srini that was here with Deloitte?

               

               

               

              Jerry

              • 4. Re: Date bug?
                Srini Dhulipalla Level 5

                I do not have the script right away with me but I can try to make you one for you.

                 

                Yes I am the same Srini..

                 

                Thanks

                Srini

                • 5. Re: Date bug?
                  Jerry62712 Level 1

                  Here is a script that mostly works:

                   

                  var monAsNum  = Date2Num($.rawValue, "YYYY-MM-DD");// works with 2 digit year
                  var monAsNum2 = Date2Num($.rawValue, "MM/DD/YYYY");// works with 4 digit year
                  var monAsNum3 = Date2Num($.rawValue, "M/DD/YYYY" );

                  var monAsNum4 = Date2Num($.rawValue, "MM/D/YYYY" );

                  var monAsNum5 = Date2Num($.rawValue, "M/D/YYYY"  );

                  //xfa.host.messageBox(Concat("Testing **Raw Source: ", $.rawValue, " Fomatted Source: ", $.formattedValue, " Raw as number: ", monAsNum));

                  //xfa.host.messageBox(Concat("Testing **m/d/yy: ", monAsNum, " mm/dd/yyyy: ", monAsNum2, " m/dd/yyyy: ", monAsNum3, " mm/d/yyyy: ", monAsNum4));

                   

                  var day = Num2Date(monAsNum, "D");

                  var month = Num2Date(monAsNum, "M");

                  var year = Num2Date(monAsNum, "Y");

                  var redone = Concat(month,"/",day+1,"/",year);

                  var rebuild = Num2Date(redone,"MM/DD/YYYY");

                  $host.messageBox(Concat("Testing **Day: ", day, " Month: ", month, " Year: ", year, " Rebuilt: ", rebuild));  // this needs work

                   

                  if (monAsNum == 0) then monAsNum = monAsNum2 endif;

                  if (monAsNum == 0) then monAsNum = monAsNum3 endif;

                  if (monAsNum == 0) then monAsNum = monAsNum4 endif;

                  if (monAsNum == 0) then monAsNum = monAsNum5 endif;

                  if (monAsNum == 0)

                  then

                    $host.messageBox("The date should be in mm/dd/yy or mm/dd/yyyy format.","Error on Date Input")

                    $.rawValue = "";

                    xfa.host.setFocus(form1.TimeEntry.MISRMondayDate);

                  else

                    var dow = Num2Date(monAsNum, "E");

                    var dowText = Num2Date(monAsNum, "EEEE");

                   

                    if (dow <> 2 and $.rawValue <> "")

                    then

                  $host.messageBox(Concat("Select a Monday, not a ", dowText),"Wrong Day")
                  $.rawValue = "";
                  xfa.host.setFocus(form1.TimeEntry.MISRMondayDate);

                    else

                  var tueAsNum = monAsNum + 1;
                  var wedAsNum = monAsNum + 2;
                  var thuAsNum = monAsNum + 3;
                  var friAsNum = monAsNum + 4;
                  var satAsNum = monAsNum + 5;
                  var sunAsNum = monAsNum + 6;

                   

                  form1.TimeEntry.EmployeeTime.OperatingDate.MondayDate.rawValue = Num2Date(monAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.TuesdayDate.rawValue = Num2Date(tueAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.WednesdayDate.rawValue = Num2Date(wedAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.ThursdayDate.rawValue = Num2Date(thuAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.FridayDate.rawValue = Num2Date(friAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.SaturdayDate.rawValue = Num2Date(satAsNum, "DD-MMM");
                  form1.TimeEntry.EmployeeTime.OperatingDate.SundayDate.rawValue = Num2Date(sunAsNum, "DD-MMM");
                  form1.TimeEntry.CATSSundayDate.rawValue = Num2Date(sunAsNum, "MMM DD, YYYY");

                    endif;

                  endif;

                   

                  Note the requirement for different formats.  The five here only cover 1/4 of the needed ones as you can also use periods, spaces, commas and who knows what else as sperators.  This has to be a bug even if it is a wad.  Internally, the date is probably a number.

                   

                  A solution, perhaps a patch only, would be to extract all the parts and put them together in a universal format.  This would eliminate the need for all the format checks.

                   

                  Using Num2Date you can extract the day, month and year, but how do you put them back into a date object?

                   

                  How can I reject the form?  If the date isn't a Monday I display a message, but I would want to reject the entry and have the user put in another one.  I've put it in an if block to simulate this, but there is probably a better way. 

                   

                  Finally, I tried to put focus (a blinking cursor) in the date field so the user can just type and not have to position the cursor manually.  It didn't work.  What did I do wrong?

                  • 6. Re: Date bug?
                    Srini Dhulipalla Level 5

                    Jerry,

                         The following steps might help in your issue..

                         I tried in my system with both m/d/yy and m/d/yyyy patterns and are working as expected..

                     

                         In your Date Control,

                              1) Place the following in EDIT Pattern.

                                        date{M/D/YYYY}|date{M/D/YY}

                              2) You can have any pattern for Display.

                              3) No pattern for Validation & Data.

                     

                         In the Exit event of your Date Control place the following test code..FormCalc as the language.

                     

                              var startAsNumber = Date2Num($.rawValue, "YYYY-MM-DD");
                              $host.messageBox(Num2Date(startAsNumber+1,"YYYY-MM-DD"));
                              $host.messageBox(Num2Date(startAsNumber+2,"YYYY-MM-DD"));

                     

                         When I tested, I am getting the correct value with both the date formats(m/d/yy and m/d/yyyy).

                     

                         Let me know if you still have issue with this approach.

                     

                    Thanks

                    Srini