From 8d3ece5d900e311a6b1548885a2535bd93fa86df Mon Sep 17 00:00:00 2001 From: Sven de Marothy Date: Wed, 23 Mar 2005 22:26:00 +0100 Subject: PR libgcj/2641, PR libgcj/9854, PR libgcj/14892, PR libgcj/18083, 2005-03-23 Sven de Marothy PR libgcj/2641, PR libgcj/9854, PR libgcj/14892, PR libgcj/18083, PR libgcj/11085: * java/util/Calendar.java (set): Use starting day of week when one is needed if none is given. * java/text/SimpleDateFormat.java (parse): Handle 1-12 and 1-24 timestamps correctly. * java/util/GregorianCalendar.java (computeTime, computeFields): HOUR should be in 0-11 format. (nonLeniencyCheck): Adjust leniency checking to that fact. (getLinearDay): Should be private. From-SVN: r96951 --- libjava/java/text/SimpleDateFormat.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libjava/java/text/SimpleDateFormat.java') diff --git a/libjava/java/text/SimpleDateFormat.java b/libjava/java/text/SimpleDateFormat.java index c1eb3cd..190b4d6 100644 --- a/libjava/java/text/SimpleDateFormat.java +++ b/libjava/java/text/SimpleDateFormat.java @@ -916,6 +916,8 @@ public class SimpleDateFormat extends DateFormat boolean is_numeric = true; int offset = 0; boolean maybe2DigitYear = false; + boolean oneBasedHour = false; + boolean oneBasedHourOfDay = false; Integer simpleOffset; String[] set1 = null; String[] set2 = null; @@ -964,12 +966,14 @@ public class SimpleDateFormat extends DateFormat break; case 'h': calendar_field = Calendar.HOUR; + oneBasedHour = true; break; case 'H': calendar_field = Calendar.HOUR_OF_DAY; break; case 'k': calendar_field = Calendar.HOUR_OF_DAY; + oneBasedHourOfDay = true; break; case 'm': calendar_field = Calendar.MINUTE; @@ -1108,6 +1112,14 @@ public class SimpleDateFormat extends DateFormat } } + // Calendar uses 0-based hours. + // I.e. 00:00 AM is midnight, not 12 AM or 24:00 + if (oneBasedHour && value == 12) + value = 0; + + if (oneBasedHourOfDay && value == 24) + value = 0; + // Assign the value and move on. calendar.set(calendar_field, value); } -- cgit v1.1