Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1226859

Date.setDate() does not wrap around end of month, or end of year, all platforms

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Not verified

      Description

      java.util.Date.setDate() method does not wrap around end of month or end of year. We
      promise this for the constructor, and we should deliver it for the other methods as well

      Steps to reproduce:
      Compile and run the following code:

      /* Tests Date accounting
       * Kevin Smith
       */

      import java.util.Date;

      public class BadDate
      {
         static public void main(String args[])
         {
            int i;
            int startDate = 27;
            int startMonth = 11;
            int startYear = 95;
            Date date = new Date(startYear, startMonth, startDate);

            // iterate through suspect dates
            for(i = 0; i < 8; ++i)
            {
               date.setDate(date.getDate() + 1);
               System.out.println(date);
            } // end for

         } // end main()

      }

      The description field as copied from bug report 1226804 follows:

      ###@###.### (Jonathan Payne)

      java.util.Date class does not understand that September has only 30 days, instead
      it thinks that September has 31 days, and that October starts on day 02.

      Steps to reproduce:
      Compile the following code
      run java with following code


      /* Tests Sept 30, 31, Oct 1, 2
       * Kevin Smith
       */

      import java.util.Date;

      public class test
      {
         static public void main(String args[])
         {
            int i;
            Date date = new Date();
            date.setMonth(8);
            date.setDate(28);

            // iterate through suspect dates
            for(i = 0; i < 8; ++i)
            {
               System.out.println(date);
               Date tomorrow = new Date(date.getTime());
               tomorrow.setDate((byte) (tomorrow.getDate() + 1));
               date = tomorrow;
            } // end for

         } // end main()

      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              duke J. Duke (Inactive)
              Reporter:
              kasmithsunw Kevin Smith (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: