Fixed UTC offset minutes to be actually minutes.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 31 May 2007 13:50:37 +0000 (13:50 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 31 May 2007 13:50:37 +0000 (13:50 +0000)
CHANGES
lib/silcutil/silctime.c
lib/silcutil/tests/test_silctime.c

diff --git a/CHANGES b/CHANGES
index 5b7d41ec6c4ab324946e6d738aecc01a36297f6a..4620accc5725e2d952da3027b47e2e95db08380f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+Thu May 31 16:49:13 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
+
+       * Fixed UTC offset minutes to be actually minutes.  Affected
+         file is lib/silcutil/silctime.c.
+
 Thu May 31 09:40:56 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * SILC Toolkit 1.1.
index 3f3a2807fea4437569271eb3203b485bbfd6daae..ea6258ae1a6af3c3319b41a2f69652da4eb86336 100644 (file)
@@ -108,6 +108,7 @@ SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
   struct tm *t;
   unsigned int msec = 0;
   time_t timeval;
+  SilcInt32 ctz = 0;
 
   if (!ret_time)
     return TRUE;
@@ -139,32 +140,24 @@ SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
 #else
 #if defined(HAVE_TIMEZONE)
   ret_time->utc_east   = timezone < 0 ? 1 : 0;
+  ctz = timezone;
+  if (ret_time->dst)
+    ctz -= 3600;
 #elif defined(HAVE_TM_GMTOFF)
   ret_time->utc_east   = t->tm_gmtoff > 0 ? 1 : 0;
+  ctz = -t->tm_gmtoff;
 #elif defined(HAVE___TM_GMTOFF)
   ret_time->utc_east   = t->__tm_gmtoff > 0 ? 1 : 0;
+  ctz = -t->__tm_gmtoff;
 #elif defined(HAVE___TM_GMTOFF__)
   ret_time->utc_east   = t->__tm_gmtoff__ > 0 ? 1 : 0;
+  ctz = -t->__tm_gmtoff__;
 #endif /* HAVE_TIMEZONE */
 
-#if defined(HAVE_TIMEZONE)
-  ret_time->utc_hour   = (ret_time->utc_east ? (-(timezone)) / 3600 :
-                         timezone / 3600);
-  if (ret_time->dst)
-    ret_time->utc_hour++;
-  ret_time->utc_minute = (ret_time->utc_east ? (-(timezone)) % 3600 :
-                         timezone % 3600);
-#elif defined(HAVE_GMTIME)
-  t = gmtime(&timeval);
-  if (t) {
-    ret_time->utc_hour   = (ret_time->utc_east
-                           ? ret_time->hour - t->tm_hour
-                           : ret_time->hour + t->tm_hour);
-    ret_time->utc_minute = (ret_time->utc_east
-                           ? ret_time->minute - t->tm_min
-                           : ret_time->minute + t->tm_min);
-  }
-#endif /* HAVE_TIMEZONE */
+  ret_time->utc_hour   = (ret_time->utc_east ? (-(ctz)) / 3600 : ctz / 3600);
+  ret_time->utc_minute = (ret_time->utc_east ? (-(ctz)) % 3600 : ctz % 3600);
+  if (ret_time->utc_minute)
+    ret_time->utc_minute /= 60;
 #endif /* SILC_WIN32 */
 
   return TRUE;
index 0bbe28148b984418275cc4fee8602441da8e9ba5..bcfa713ebd44e839aafd8f978d19a9d060023858 100644 (file)
@@ -22,6 +22,7 @@ int main(int argc, char **argv)
   SILC_LOG_DEBUG(("day       : %d", curtime.day));
   SILC_LOG_DEBUG(("hour      : %d", curtime.hour));
   SILC_LOG_DEBUG(("minute    : %d", curtime.minute));
+  SILC_LOG_DEBUG(("second    : %d", curtime.second));
   SILC_LOG_DEBUG(("msecond   : %d", curtime.msecond));
   SILC_LOG_DEBUG(("utc_hour  : %d", curtime.utc_hour));
   SILC_LOG_DEBUG(("utc_min   : %d", curtime.utc_minute));