Name: boT120536 Date: 12/08/2000 java version "1.2.2" Classic VM (build JDK-1.2.2-W, native threads, symcjit) In java documentation of SimpleDateFormat it is specified that the symbol/pattern 'h' takes the value from 1 to 12 hour in am/pm. But actually it takes values from 0-12 hours. Infact it should give an error while calling parse function when the hour is specified as 0. Here is the Sample code which demonstrates the bug import java.text.*; import java.util.*; public class TestForBugInSimpleDateFormat { public static void main(String arg[]) { //This is valid value for format "hh:mmaa" String strValidTime = "12:30AM"; /*This is not a valid value for format "hh:mmaa" as h take value from 1-12 and 0 is invalid value*/ String strInValidTime = "00:30AM"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(); simpleDateFormat.applyPattern("hh:mmaa"); simpleDateFormat.setLenient(false); try { Date date1 = simpleDateFormat.parse(strValidTime); System.out.println("Date1 = " + date1); //Actually here it should give parse exception but it doesn't Date date2 = simpleDateFormat.parse(strInValidTime); System.out.println("Date2 = " + date2); } catch(Exception exception) { exception.printStackTrace(); } } } (Review ID: 113487) ====================================================================== Name: nt126004 Date: 09/11/2002 FULL PRODUCT VERSION : J2SE 1.4.0-b92 FULL OPERATING SYSTEM VERSION : WINDOWS NT 4.0 WORSTATION A DESCRIPTION OF THE PROBLEM : Using the defined time patterns "h" (1-12) and "k" (1-24), one should not be able to parse "00:01 AM" without an error or the error index in the ParsePosition at -1. When parsing "13:01 PM" with a "hh:mm a" pattern, the error index is corretly set to 8. But if i try to parse "00:01 PM" with the same pattern, no error is detected and the error index stays at -1. Same behaviour with the "kk:mm a" pattern which accept "00:01 PM" but not "25:01 PM". Is this a bug or a problem in the documentation? EXPECTED VERSUS ACTUAL BEHAVIOR : It looks like the "h" pattern is really 0-12 and the "k" pattern 0-24. REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.text.*; import java.util.*; public class BugTest { public static void main (String[] args) { SimpleDateFormat formater_KK = new SimpleDateFormat("KK:mm a"); // (0-11) SimpleDateFormat formater_hh = new SimpleDateFormat("hh:mm a"); // (1-12) SimpleDateFormat formater_kk = new SimpleDateFormat("kk:mm a"); // (1-24) formater_KK.setLenient(false); formater_kk.setLenient(false); formater_hh.setLenient(false); ParsePosition pos_1 = new ParsePosition(0); Date date_1 = formater_KK.parse("12:01 PM",pos_1); ParsePosition pos_2 = new ParsePosition(0); Date date_2 = formater_hh.parse("13:01 PM",pos_2); ParsePosition pos_3 = new ParsePosition(0); Date date_3 = formater_hh.parse("00:01 AM",pos_3); ParsePosition pos_4 = new ParsePosition(0); Date date_4 = formater_kk.parse("00:01 PM",pos_4); System.out.println("date_1: " + date_1 + " - index: " + pos_1.getIndex() + " - error index: " + pos_1.getErrorIndex()); // null // OK System.out.println("date_2: " + date_2 + " - index: " + pos_2.getIndex() + " - error index: " + pos_2.getErrorIndex()); // null // OK System.out.println("date_3: " + date_3 + " - index: " + pos_3.getIndex() + " - error index: " + pos_3.getErrorIndex()); // Thu Jan 01 12:01:00 GMT 1970 // NOT OK should be null ! System.out.println("date_4: " + date_4 + " - index: " + pos_4.getIndex() + " - error index: " + pos_4.getErrorIndex()); // Thu Jan 01 00:01:00 GMT 1970 // NOT OK should be null ! } } ---------- END SOURCE ---------- (Review ID: 153627) ======================================================================
|