Re: Bug report: java.util.GregorianCalendar
Hi, On Mon, 2003-09-01 at 23:42, Mark Wielaard wrote: > I added your observation about the first day of the month to the test. > But Jochen his email indicated that for Julian dates we also need to > correct some things. So I also added tests for that. The resulting Mauve > tests is attached. And the results with your patches applied gives: > > FAIL: gnu.testlet.java.util.GregorianCalendar.first: day 1-12-1400 (number 1) > got 2 but expected 1 > FAIL: gnu.testlet.java.util.GregorianCalendar.first: week 1-12-1400 (number 1) > got 2 but expected 1 > FAIL: gnu.testlet.java.util.GregorianCalendar.first: day 1-12-1404 (number 1) > got 2 but expected 1 > 3 of 312 tests failed It seems that email to the classpath mailinglist is very slow again (I didn't got this message back through the list yet) but I already found my own thinko: for (int year = startYear; year <= startYear + 5; year++) for (int month = 0; month <= 12; month++) month <= 12, should be month < 12. With that your patches make GregorianCalendar pass all these tests. We still need to look at tests for overflow/roll-over for days and months since that should actually work correctly. But if you are confident that these changes are correct then we can check these in now. BTW. We can accept small one-liners like the above without worrying about copyrights. But if you want to contribute bigger changes, please see http://www.gnu.org/software/classpath/docs/hacking.html#SEC2 and/or contact me off-list so we can make sure all your contributions can be easily and quickly accepted. Thanks, Mark ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
Hi, On Fri, 2003-08-29 at 08:58, Ito Kazumitsu wrote: > In message "Re: Bug report: java.util.GregorianCalendar" > on 03/08/28, Ito Kazumitsu <[EMAIL PROTECTED]> writes: > > > And I have found another bug shown by the attached program. > > This bug seems to have something to do with leap yeas. > > If this bug is fixed, my patch about the WEEK_OF_MONTH will > > work. > > This is my patch for this bug. Thanks again! I added your observation about the first day of the month to the test. But Jochen his email indicated that for Julian dates we also need to correct some things. So I also added tests for that. The resulting Mauve tests is attached. And the results with your patches applied gives: FAIL: gnu.testlet.java.util.GregorianCalendar.first: day 1-12-1400 (number 1) got 2 but expected 1 FAIL: gnu.testlet.java.util.GregorianCalendar.first: week 1-12-1400 (number 1) got 2 but expected 1 FAIL: gnu.testlet.java.util.GregorianCalendar.first: day 1-12-1404 (number 1) got 2 but expected 1 3 of 312 tests failed Cheers, Mark // Tags: JDK1.1 // Copyright (C) 2003 Free Software Foundation, Inc. // Contributed by Mark Wielaard ([EMAIL PROTECTED]) // This file is part of Mauve. // Mauve is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // Mauve is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Mauve; see the file COPYING. If not, write to // the Free Software Foundation, 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. package gnu.testlet.java.util.GregorianCalendar; import gnu.testlet.Testlet; import gnu.testlet.TestHarness; import java.util.*; /** * Checks that the first day of the month is day one and that the * first week is week one. */ public class first implements Testlet { private TestHarness harness; public void test (TestHarness harness) { this.harness = harness; // Julian dates. testYears(1400); // Gregorian dates. testYears(2000); } private void testYears(int startYear) { for (int year = startYear; year <= startYear + 5; year++) for (int month = 0; month <= 12; month++) { GregorianCalendar cal = new GregorianCalendar(year, month, 1); harness.check(cal.get(Calendar.DAY_OF_MONTH), 1, "day 1-" + month + "-" + year); harness.check(cal.get(Calendar.WEEK_OF_MONTH), 1, "week 1-" + month + "-" + year); } } } ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
On Friday 29 August 2003 08:58, Ito Kazumitsu wrote: > > This is my patch for this bug. > > --- java/util/GregorianCalendar.java.orig Thu Aug 14 13:32:06 2003 > +++ java/util/GregorianCalendar.java Fri Aug 29 15:56:51 2003 > @@ -264,8 +264,10 @@ > // > // The additional leap year factor accounts for the fact that > // a leap day is not seen on Jan 1 of the leap year. > +// And on and after the leap day, the leap day has already been > +// included in dayOfYear. > int gregOffset = (year / 400) - (year / 100) + 2; > - if (isLeapYear (year, true) && dayOfYear < 31 + 29) > + if (isLeapYear (year, true)) > --gregOffset; Although I authored this code, I haven't followed the patches for GregorianCalendar lately. I think you are right that the dayOfYear doesn't matter here, but this should also apply for the julian case i.e. outside of the if(gregorian). Also there is almost the same code in getLinearDay that needs fixing too. This function is used when transforming a linear day in day/month/year and it is known whether it is gregorian or julian. A trickier change would subtract year by one at the beginning of the function, replace 1970 by 1969 and get rid of the isLeapYear case. This saves the extra case distinction and isLeapYear call (and makes the code even less understandable). Jochen -- Jochen Hoenicke, University of Oldenburg, 26111 Oldenburg, Germany Email: [EMAIL PROTECTED] Tel: +49 441 798 3124 pgp0.pgp Description: signature ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
In message "Re: Bug report: java.util.GregorianCalendar" on 03/08/28, Ito Kazumitsu <[EMAIL PROTECTED]> writes: > And I have found another bug shown by the attached program. > This bug seems to have something to do with leap yeas. > If this bug is fixed, my patch about the WEEK_OF_MONTH will > work. This is my patch for this bug. --- java/util/GregorianCalendar.java.orig Thu Aug 14 13:32:06 2003 +++ java/util/GregorianCalendar.javaFri Aug 29 15:56:51 2003 @@ -264,8 +264,10 @@ // // The additional leap year factor accounts for the fact that // a leap day is not seen on Jan 1 of the leap year. +// And on and after the leap day, the leap day has already been +// included in dayOfYear. int gregOffset = (year / 400) - (year / 100) + 2; - if (isLeapYear (year, true) && dayOfYear < 31 + 29) + if (isLeapYear (year, true)) --gregOffset; time += gregOffset * (24 * 60 * 60 * 1000L); } @@ -609,7 +611,7 @@ // 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 + 6) / 7; +fields[WEEK_OF_MONTH] = (fields[DAY_OF_MONTH] - relativeWeekday + 12) / 7; int weekOfYear = (fields[DAY_OF_YEAR] - relativeWeekday + 6) / 7; ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
BTW, if you're interested in fixing GregorianCalendar, there are a couple of reports against libgcj for it: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=2641 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=9854 Tom ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
Mark, For the record, your 'GregorianCalendar.first' testcase runs without any failures under Sun JDK 1.4.1. This suggests to me that any failures you are seeing are not the fault of your testcase! -- Steve ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
In message "Re: Bug report: java.util.GregorianCalendar" on 03/08/28, Mark Wielaard <[EMAIL PROTECTED]> writes: > Thanks. I finally looked into this. > I created a simple Mauve test case for this (attached), but even with > your patch it still gives a few failures. > > FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-3-2000 (number 1) > got 2 but expected 1 > FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-6-2000 (number 1) > got 2 but expected 1 > FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-4-2004 (number 1) > got 2 but expected 1 > FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-12-2004 (number 1) > got 2 but expected 1 > 4 of 72 tests failed > > Could you see if my test or GregorianCalendar is faulty? Thank you for your attention. First, the number of month is 0-based. So > for (int month = 1; month <= 12; month++) should be for (int month = 0; month < 12; month++) And I have found another bug shown by the attached program. This bug seems to have something to do with leap yeas. If this bug is fixed, my patch about the WEEK_OF_MONTH will work. $ cat TestGregorianCalendar.java import java.util.*; public class TestGregorianCalendar { public static void main(String[] args) { for (int year = 2000; year <= 2005; year++) { for (int month = 0; month < 12; month++) { GregorianCalendar cal = new GregorianCalendar(year, month, 1); if (cal.get(Calendar.DAY_OF_MONTH) != 1) { System.out.println ( cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH)); } } } } } $ java TestGregorianCalendar 2000-3-2 2000-4-2 2000-5-2 2000-6-2 2000-7-2 2000-8-2 2000-9-2 2000-10-2 2000-11-2 2000-12-2 2004-3-2 2004-4-2 2004-5-2 2004-6-2 2004-7-2 2004-8-2 2004-9-2 2004-10-2 2004-11-2 2004-12-2 ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath
Re: Bug report: java.util.GregorianCalendar
Hi, On Mon, 2003-07-28 at 07:43, Ito Kazumitsu wrote: > Sun's API document says about java.util.Calendar.WEEK_OF_MONTH, > "The first week of the month, as defined by getFirstDayOfWeek() and > getMinimalDaysInFirstWeek(), has value 1." > > But GNU Classpath's java.util.GregorianCalendar returns 0 for the > first week of the month except for those special months whose > first day is Sunday (e.g. Jun 2003). > > Here is my patch: Thanks. I finally looked into this. I created a simple Mauve test case for this (attached), but even with your patch it still gives a few failures. FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-3-2000 (number 1) got 2 but expected 1 FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-6-2000 (number 1) got 2 but expected 1 FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-4-2004 (number 1) got 2 but expected 1 FAIL: gnu.testlet.java.util.GregorianCalendar.first: 1-12-2004 (number 1) got 2 but expected 1 4 of 72 tests failed Could you see if my test or GregorianCalendar is faulty? Thanks, Mark // Tags: JDK1.1 // Copyright (C) 2003 Free Software Foundation, Inc. // Contributed by Mark Wielaard ([EMAIL PROTECTED]) // This file is part of Mauve. // Mauve is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // Mauve is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Mauve; see the file COPYING. If not, write to // the Free Software Foundation, 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. package gnu.testlet.java.util.GregorianCalendar; import gnu.testlet.Testlet; import gnu.testlet.TestHarness; import java.util.*; /** * Checks that the first week of the month is week one. */ public class first implements Testlet { public void test (TestHarness harness) { for (int year = 2000; year <= 2005; year++) for (int month = 1; month <= 12; month++) { GregorianCalendar cal = new GregorianCalendar(year, month, 1); harness.check(cal.get(Calendar.WEEK_OF_MONTH), 1, 1 + "-" + month + "-" + year); } } } ___ Classpath mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/classpath