aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorSven de Marothy <sven@physto.se>2005-03-23 22:26:00 +0100
committerTom Tromey <tromey@gcc.gnu.org>2005-03-23 21:26:00 +0000
commit8d3ece5d900e311a6b1548885a2535bd93fa86df (patch)
treefdb34ce03f86ab0625684dbe5615ad44586e2228 /libjava/java
parent85c4f26a8651192648d1d4ce37009d838abe4152 (diff)
downloadgcc-8d3ece5d900e311a6b1548885a2535bd93fa86df.zip
gcc-8d3ece5d900e311a6b1548885a2535bd93fa86df.tar.gz
gcc-8d3ece5d900e311a6b1548885a2535bd93fa86df.tar.bz2
PR libgcj/2641, PR libgcj/9854, PR libgcj/14892, PR libgcj/18083,
2005-03-23 Sven de Marothy <sven@physto.se> 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
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/text/SimpleDateFormat.java12
-rw-r--r--libjava/java/util/Calendar.java6
-rw-r--r--libjava/java/util/GregorianCalendar.java45
3 files changed, 41 insertions, 22 deletions
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);
}
diff --git a/libjava/java/util/Calendar.java b/libjava/java/util/Calendar.java
index 0e9284c..7faaeee 100644
--- a/libjava/java/util/Calendar.java
+++ b/libjava/java/util/Calendar.java
@@ -706,6 +706,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;
@@ -715,6 +717,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;
@@ -733,6 +737,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/libjava/java/util/GregorianCalendar.java b/libjava/java/util/GregorianCalendar.java
index 710dd56..d036cd6 100644
--- a/libjava/java/util/GregorianCalendar.java
+++ b/libjava/java/util/GregorianCalendar.java
@@ -275,7 +275,6 @@ public class GregorianCalendar extends Calendar
* Constructs a new GregorianCalendar representing midnight on the
* given date with the default time zone and locale.
*
- *
* @param year corresponds to the YEAR time field.
* @param month corresponds to the MONTH time field.
* @param day corresponds to the DAY time field.
@@ -478,7 +477,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))
@@ -564,10 +563,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
@@ -584,7 +591,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;
}
@@ -602,11 +609,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];
@@ -709,15 +712,15 @@ public class GregorianCalendar extends Calendar
* @param gregorian <code>true</code>, if we should use the Gregorian rules.
* @return the days since the epoch, may be negative.
*/
- public long getLinearDay(int year, int dayOfYear, boolean gregorian)
- {
- // The 13 is the number of days, that were omitted in the Gregorian
- // Calender until the epoch.
- // We shift right by 2 instead of dividing by 4, to get correct
- // results for negative years (and this is even more efficient).
- long julianDay = (year - 1) * 365L + ((year - 1) >> 2) + (dayOfYear - 1)
- - EPOCH_DAYS; // gregorian days from 1 to epoch.
-
+ private long getLinearDay(int year, int dayOfYear, boolean gregorian)
+ {
+ // The 13 is the number of days, that were omitted in the Gregorian
+ // Calender until the epoch.
+ // We shift right by 2 instead of dividing by 4, to get correct
+ // results for negative years (and this is even more efficient).
+ long julianDay = (year - 1) * 365L + ((year - 1) >> 2) + (dayOfYear - 1)
+ - EPOCH_DAYS; // gregorian days from 1 to epoch.
+
if (gregorian)
{
// subtract the days that are missing in gregorian calendar
@@ -858,7 +861,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);
@@ -925,9 +928,7 @@ public class GregorianCalendar extends Calendar
}
int maxDay = getActualMaximum(DAY_OF_MONTH);
if (fields[DAY_OF_MONTH] > maxDay)
- {
- fields[DAY_OF_MONTH] = maxDay;
- }
+ fields[DAY_OF_MONTH] = maxDay;
set(YEAR, fields[YEAR]);
set(MONTH, fields[MONTH]);
break;