This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Timezone fixes PR 1358 (formerly PR 331)


Folks,
I've checked in some fixes which take care of PR 1358 (java.util.Date,
java.util.GregorianCalendar and some associated timezone problems).
Enjoy!
--warrenl


2000-12-27  Warren Levy  <warrenl@redhat.com>

        Fix for PR libgcj/1358:
        * java/lang/System.java: Update Copyright date properly.
        * java/util/Calendar.java: Fix typo in comment.
        (set): Set 24-hour clock hour instead of 12-hour clock hour.
        * java/util/GregorianCalendar.java (GregorianCalendar): Properly
        initialize times.  Spec says to set H:M:S values to zero only if
        a date is given.
        * java/util/TimeZone.java (getDefaultDisplayName): Casts to char
        needed for evaluating numbers '0' to '9' in printouts of GMT offsets.
        * java/util/natGregorianCalendar.cc (computeTime): Properly handle
        timezones and GMT offsets, being careful to account for units of
        milliseconds vs. seconds.



Index: java/lang/System.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/System.java,v
retrieving revision 1.5
diff -u -p -r1.5 System.java
--- System.java	2000/11/26 01:48:04	1.5
+++ System.java	2000/12/28 05:41:08
@@ -1,6 +1,6 @@
 // System.java - System-specific info.
 
-/* Copyright (C) 1998, 1999  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
 
    This file is part of libgcj.
 
Index: java/util/Calendar.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/Calendar.java,v
retrieving revision 1.7
diff -u -p -r1.7 Calendar.java
--- Calendar.java	2000/10/27 10:33:46	1.7
+++ Calendar.java	2000/12/28 05:41:08
@@ -257,7 +257,7 @@ public abstract class Calendar implement
    */
   public static final int DECEMBER = 11;
   /**
-   * Constant representing Undecimber. This is an artifical name useful
+   * Constant representing Undecimber. This is an artificial name useful
    * for lunar calendars.
    */
   public static final int UNDECIMBER = 12;
@@ -581,9 +581,9 @@ public abstract class Calendar implement
   public final void set(int year, int month, int date, int hour, int minute)
   {
     set(year, month, date);
-    fields[HOUR] = hour;
+    fields[HOUR_OF_DAY] = hour;
     fields[MINUTE] = minute;
-    isSet[HOUR] = isSet[MINUTE] = true;
+    isSet[HOUR_OF_DAY] = isSet[MINUTE] = true;
   }
 
   /**
Index: java/util/GregorianCalendar.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/GregorianCalendar.java,v
retrieving revision 1.7
diff -u -p -r1.7 GregorianCalendar.java
--- GregorianCalendar.java	2000/12/19 07:48:54	1.7
+++ GregorianCalendar.java	2000/12/28 05:41:08
@@ -115,23 +115,20 @@ public class GregorianCalendar extends C
   public GregorianCalendar (int year, int month, int date)
   {
     this();
-    setDefaultTime ();
-    set (year, month, date);
+    set (year, month, date, 0, 0, 0);
   }
 
   public GregorianCalendar (int year, int month, int date,
 			    int hour, int minute)
   {
     this();
-    setDefaultTime ();
-    set (year, month, date, hour, minute);
+    set (year, month, date, hour, minute, 0);
   }
 
   public GregorianCalendar (int year, int month, int date,
 			    int hour, int minute, int second)
   {
     this();
-    setDefaultTime ();
     set (year, month, date, hour, minute, second);
   }
 
Index: java/util/TimeZone.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/TimeZone.java,v
retrieving revision 1.8
diff -u -p -r1.8 TimeZone.java
--- TimeZone.java	2000/12/04 10:24:38	1.8
+++ TimeZone.java	2000/12/28 05:41:08
@@ -896,8 +896,9 @@ public abstract class TimeZone implement
     int hours = offset / 60;
     int minutes = offset % 60;
 
-    sb.append('0' + hours / 10).append('0' + hours % 10).append(':');
-    sb.append('0' + minutes / 10).append('0' + minutes % 10);
+    sb.append((char) ('0' + hours / 10)).append((char) ('0' + hours % 10));
+    sb.append(':');
+    sb.append((char) ('0' + minutes / 10)).append((char) ('0' + minutes % 10));
     return sb.toString();
   }
 
Index: java/util/natGregorianCalendar.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/natGregorianCalendar.cc,v
retrieving revision 1.7
diff -u -p -r1.7 natGregorianCalendar.cc
--- natGregorianCalendar.cc	2000/10/27 11:53:53	1.7
+++ natGregorianCalendar.cc	2000/12/28 05:41:08
@@ -39,15 +39,16 @@ java::util::GregorianCalendar::computeTi
   // Adjust for local timezone (introduced by mktime) and our
   // timezone.
 #if defined (STRUCT_TM_HAS_GMTOFF)
-  t += tim.tm_gmtoff;
+  t -= tim.tm_gmtoff;
 #elif defined (HAVE_TIMEZONE)
-  t -= timezone;
+  t += timezone;
 #endif
-  java::util::TimeZone *zone = getTimeZone ();
-  t += zone->getRawOffset();
-
   // Adjust for milliseconds.
   time = t * (jlong) 1000 + elements(fields)[MILLISECOND];
+
+  // Now adjust for the real timezone, i.e. our timezone, which is in millis.
+  java::util::TimeZone *zone = getTimeZone ();
+  time += zone->getRawOffset();
 
   isTimeSet = true;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]