Patch: TimeZone portability fix

Warren Levy warrenl@redhat.com
Fri Jan 26 13:56:00 GMT 2001


Folks,
This one's pretty self-explanatory.  Since it is a portability issue I'm
checking it in while the tree is slushy.
--warrenl


2001-01-26  Warren Levy  <warrenl@redhat.com>

        * java/lang/natSystem.cc (getSystemTimeZone): Only use tm_gmtoff
        and timezone if they are available on the system.


Index: natSystem.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natSystem.cc,v
retrieving revision 1.33
diff -u -p -r1.33 natSystem.cc
--- natSystem.cc	2001/01/12 19:16:05	1.33
+++ natSystem.cc	2001/01/26 21:50:31
@@ -240,15 +240,28 @@ getpwuid_adaptor(T_passwd * (*getpwuid_r
 jstring
 java::lang::System::getSystemTimeZone (void)
 {
+  struct tm *tim;
   time_t current_time;
   char **tzinfo, *tzid;
   long tzoffset;
 
   current_time = time(0);
 
-  mktime(localtime(&current_time));
+  mktime(tim = localtime(&current_time));
+#ifdef STRUCT_TM_HAS_GMTOFF
+  tzoffset = -(tim->tm_gmtoff);	// tm_gmtoff is secs EAST of UTC.
+#elif HAVE_TIMEZONE
+  tzoffset = timezone;		// timezone is secs WEST of UTC.
+#else
+  // FIXME: there must be another global if neither tm_gmtoff nor timezone
+  // is available, esp. if tzname is valid.
+  // Richard Earnshaw <rearnsha@arm.com> has suggested using difftime to
+  // calculate between gmtime and localtime (and accounting for possible
+  // daylight savings time) as an alternative.  Also note that this same
+  // issue exists in java/util/natGregorianCalendar.cc.
+  tzoffset = 0L;
+#endif
   tzinfo = tzname;
-  tzoffset = timezone;
 
   if ((tzoffset % 3600) == 0)
     tzoffset = tzoffset / 3600;



More information about the Java-patches mailing list