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

Format "ha" is unable to parse hours 10-12

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 7u71
    • core-libs
    • b122
    • x86_64
    • windows_7
    • Verified

      FULL PRODUCT VERSION :
      java version "1.7.0_71"
      Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)


      Also verified it was failing in
      java version "1.6.0_45"
      Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Running Java through Juno.

      A DESCRIPTION OF THE PROBLEM :
      The specifications for SimpleDateFormat claim that the "h" char is valid for hours 10-12. Although when we attempt to parse "10AM", "11AM", "12AM", "10PM", etc. with the format "ha" it throws a parse exception.





      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a SimpleDateFormat class with the "ha" format. Attempt to parse "12AM". Notice a ParseException is thrown.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No Exception
      ACTUAL -
      Failed to parse 10AM
      Failed to parse 10PM
      Failed to parse 11AM
      Failed to parse 11PM
      Failed to parse 12AM
      Failed to parse 12PM


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Sample Code -

      import java.text.ParseException;
      import java.text.SimpleDateFormat;

      public class test{
        /**
         * @param args
         * @throws ParseException
         */
        public static void main(String[] args){
          // SimpleDateFormat timeslotDateTimeFormat = new SimpleDateFormat("MMM d, yyyy ha");
          SimpleDateFormat timeslotDateTimeFormat = new SimpleDateFormat("ha");

          String time = "$";
          // String date = "Jan 27, 2015";
          String am = "AM";
          String pm = "PM";
          int counter = 1;
          while(counter < 13){
            try{
              time = counter + am;
              // time = date + " " + counter + am;
              timeslotDateTimeFormat.parse(time);
            }catch(ParseException e){
              System.out.println("Failed to parse " + time);
            }
            try{
              time = counter + pm;
              // time = date + " " + counter + pm;
              timeslotDateTimeFormat.parse(time);
            }catch(ParseException e){
              System.out.println("Failed to parse " + time);
            }
            counter++;
          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I have begun using the "hha" format, but this requires me to parse out the leading zeros of the single digit times.

            nishjain Nishit Jain
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: