summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Benson <gbenson@redhat.com>2007-04-05 12:52:44 +0000
committerGary Benson <gbenson@redhat.com>2007-04-05 12:52:44 +0000
commitea8c2f2eb844a744b0368c4fef738d6559915bdb (patch)
tree6d06c208c6de279830cdba1fe0ac8ed84cb40660
parent9650bcc78c6813e6e5b5c44e98df2922a140785c (diff)
downloadclasspath-ea8c2f2eb844a744b0368c4fef738d6559915bdb.tar.gz
2007-04-05 Gary Benson <gbenson@redhat.com>
* java/util/GregorianCalendar.java (computeFields): Fix WEEK_OF_MONTH calculation.
-rw-r--r--ChangeLog5
-rw-r--r--java/util/GregorianCalendar.java17
2 files changed, 19 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index d91d3fb65..3f92a5ea3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-05 Gary Benson <gbenson@redhat.com>
+
+ * java/util/GregorianCalendar.java
+ (computeFields): Fix WEEK_OF_MONTH calculation.
+
2007-04-05 Christian Thalinger <twisti@complang.tuwien.ac.at>
PR classpath/22800:
diff --git a/java/util/GregorianCalendar.java b/java/util/GregorianCalendar.java
index eb64f1c3f..6eb7ce84e 100644
--- a/java/util/GregorianCalendar.java
+++ b/java/util/GregorianCalendar.java
@@ -1,5 +1,5 @@
/* java.util.GregorianCalendar
- Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004
+ Copyright (C) 1998, 1999, 2001, 2002, 2003, 2004, 2007
Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -841,13 +841,24 @@ public class GregorianCalendar extends Calendar
// which day of the week are we (0..6), relative to getFirstDayOfWeek
int relativeWeekday = (7 + fields[DAY_OF_WEEK] - getFirstDayOfWeek()) % 7;
- fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 12) / 7;
+ // which day of the week is the first of this month?
+ // nb 35 is the smallest multiple of 7 that ensures that
+ // the left hand side of the modulo operator is positive.
+ int relativeWeekdayOfFirst = (relativeWeekday - fields[DAY_OF_MONTH]
+ + 1 + 35) % 7;
+
+ // which week of the month is the first of this month in?
+ int minDays = getMinimalDaysInFirstWeek();
+ int weekOfFirst = ((7 - relativeWeekdayOfFirst) >= minDays) ? 1 : 0;
+
+ // which week of the month is this day in?
+ fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH]
+ + relativeWeekdayOfFirst - 1) / 7 + weekOfFirst;
int weekOfYear = (fields[DAY_OF_YEAR] - relativeWeekday + 6) / 7;
// Do the Correction: getMinimalDaysInFirstWeek() is always in the
// first week.
- int minDays = getMinimalDaysInFirstWeek();
int firstWeekday = (7 + getWeekDay(fields[YEAR], minDays)
- getFirstDayOfWeek()) % 7;
if (minDays - firstWeekday < 1)