summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven de Marothy <sven@physto.se>2005-03-09 22:29:20 +0000
committerSven de Marothy <sven@physto.se>2005-03-09 22:29:20 +0000
commit61bd2a14607007e639d0da0482f9da4eb03a9a16 (patch)
tree2ddbcec8694d3973ff3dfc69d6c9d29670b4799f
parentd188f7f0747742a8ee5bb5686abc86d0464a0386 (diff)
downloadclasspath-61bd2a14607007e639d0da0482f9da4eb03a9a16.tar.gz
2005-03-09 Sven de Marothy <sven@physto.se>
* 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 (computeTime, computeFields): HOUR should be in 0-11 format. (nonLeniencyCheck): Adjust leniency checking to that fact.
-rw-r--r--ChangeLog10
-rw-r--r--java/text/SimpleDateFormat.java12
-rw-r--r--java/util/Calendar.java6
-rw-r--r--java/util/GregorianCalendar.java22
4 files changed, 41 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 898e2eafb..4e4460506 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2005-03-09 Sven de Marothy <sven@physto.se>
+ * 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
+ (computeTime, computeFields): HOUR should be in 0-11 format.
+ (nonLeniencyCheck): Adjust leniency checking to that fact.
+
+2005-03-09 Sven de Marothy <sven@physto.se>
+
* gnu/java/locale/Calendar.java,
gnu/java/locale/Calendar_nl.java,
gnu/java/locale/Calendar_de.java,
diff --git a/java/text/SimpleDateFormat.java b/java/text/SimpleDateFormat.java
index c1eb3cd3a..190b4d624 100644
--- a/java/text/SimpleDateFormat.java
+++ b/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);
}
diff --git a/java/util/Calendar.java b/java/util/Calendar.java
index a3b021573..0056f4821 100644
--- a/java/util/Calendar.java
+++ b/java/util/Calendar.java
@@ -723,6 +723,8 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[WEEK_OF_YEAR] = false;
break;
case WEEK_OF_MONTH: // pattern 2
+ if (! isSet[DAY_OF_WEEK])
+ fields[DAY_OF_WEEK] = getFirstDayOfWeek();
isSet[YEAR] = true;
isSet[MONTH] = true;
isSet[DAY_OF_WEEK] = true;
@@ -732,6 +734,8 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[WEEK_OF_YEAR] = false;
break;
case DAY_OF_WEEK_IN_MONTH: // pattern 3
+ if (! isSet[DAY_OF_WEEK])
+ fields[DAY_OF_WEEK] = getFirstDayOfWeek();
isSet[YEAR] = true;
isSet[MONTH] = true;
isSet[DAY_OF_WEEK] = true;
@@ -750,6 +754,8 @@ public abstract class Calendar implements Serializable, Cloneable
isSet[DAY_OF_WEEK_IN_MONTH] = false;
break;
case WEEK_OF_YEAR: // pattern 5
+ if (! isSet[DAY_OF_WEEK])
+ fields[DAY_OF_WEEK] = getFirstDayOfWeek();
isSet[YEAR] = true;
isSet[DAY_OF_WEEK] = true;
isSet[MONTH] = false;
diff --git a/java/util/GregorianCalendar.java b/java/util/GregorianCalendar.java
index 5972599fb..d4c2a12d1 100644
--- a/java/util/GregorianCalendar.java
+++ b/java/util/GregorianCalendar.java
@@ -474,7 +474,7 @@ public class GregorianCalendar extends Calendar
if (isSet[AM_PM] && fields[AM_PM] != AM && fields[AM_PM] != PM)
throw new IllegalArgumentException("Illegal AM_PM.");
- if (isSet[HOUR] && (fields[HOUR] < 0 || fields[HOUR] > 12))
+ if (isSet[HOUR] && (fields[HOUR] < 0 || fields[HOUR] > 11))
throw new IllegalArgumentException("Illegal HOUR.");
if (isSet[HOUR_OF_DAY]
&& (fields[HOUR_OF_DAY] < 0 || fields[HOUR_OF_DAY] > 23))
@@ -560,10 +560,18 @@ public class GregorianCalendar extends Calendar
// 3: YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
if (isSet[DAY_OF_WEEK_IN_MONTH])
{
+ if (fields[DAY_OF_WEEK_IN_MONTH] < 0)
+ {
+ month++;
+ first = getFirstDayOfMonth(year, month);
+ day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH]);
+ }
+ else
+ day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);
+
int offs = fields[DAY_OF_WEEK] - first;
if (offs < 0)
offs += 7;
- day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);
day += offs;
}
else
@@ -580,7 +588,7 @@ public class GregorianCalendar extends Calendar
day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);
offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
- if (offs < 0)
+ if (offs <= 0)
offs += 7;
day += offs;
}
@@ -598,11 +606,7 @@ public class GregorianCalendar extends Calendar
{
hour = fields[HOUR];
if (fields[AM_PM] == PM)
- if (hour != 12) /* not Noon */
- hour += 12;
- /* Fix the problem of the status of 12:00 AM (midnight). */
- if (fields[AM_PM] == AM && hour == 12)
- hour = 0;
+ hour += 12;
}
else
hour = fields[HOUR_OF_DAY];
@@ -854,7 +858,7 @@ public class GregorianCalendar extends Calendar
int hourOfDay = millisInDay / (60 * 60 * 1000);
fields[AM_PM] = (hourOfDay < 12) ? AM : PM;
int hour = hourOfDay % 12;
- fields[HOUR] = (hour == 0) ? 12 : hour;
+ fields[HOUR] = hour;
fields[HOUR_OF_DAY] = hourOfDay;
millisInDay %= (60 * 60 * 1000);
fields[MINUTE] = millisInDay / (60 * 1000);