diff options
author | Gary Benson <gbenson@redhat.com> | 2007-04-05 12:52:44 +0000 |
---|---|---|
committer | Gary Benson <gbenson@redhat.com> | 2007-04-05 12:52:44 +0000 |
commit | ea8c2f2eb844a744b0368c4fef738d6559915bdb (patch) | |
tree | 6d06c208c6de279830cdba1fe0ac8ed84cb40660 /java/util | |
parent | 9650bcc78c6813e6e5b5c44e98df2922a140785c (diff) | |
download | classpath-ea8c2f2eb844a744b0368c4fef738d6559915bdb.tar.gz |
2007-04-05 Gary Benson <gbenson@redhat.com>
* java/util/GregorianCalendar.java
(computeFields): Fix WEEK_OF_MONTH calculation.
Diffstat (limited to 'java/util')
-rw-r--r-- | java/util/GregorianCalendar.java | 17 |
1 files changed, 14 insertions, 3 deletions
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) |