Used the remaining 2 bits from SilcTime structure.
authorPekka Riikonen <priikone@silcnet.org>
Sat, 21 Oct 2006 13:46:24 +0000 (13:46 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 21 Oct 2006 13:46:24 +0000 (13:46 +0000)
lib/silcutil/silctime.c
lib/silcutil/silctime.h

index 13575e57ee62132c5ebdb8f1e592a7216e4b5879..da49445ac8a079a8a3130b1c9f80db3eda120364 100644 (file)
 
 #include "silc.h"
 
+/* Fills the SilcTime structure with correct values */
+
+static SilcBool silc_time_fill(SilcTime time,
+                              unsigned int year,
+                              unsigned int month,
+                              unsigned int day,
+                              unsigned int hour,
+                              unsigned int minute,
+                              unsigned int second)
+{
+  if (year > (1 << 15))
+    return FALSE;
+  if (month < 1 || month > 12)
+    return FALSE;
+  if (day < 1 || day > 31)
+    return FALSE;
+  if (hour > 23)
+    return FALSE;
+  if (minute > 60)
+    return FALSE;
+  if (second > 61)
+    return FALSE;
+
+  time->year = year;
+  time->month = month;
+  time->day = day;
+  time->hour = hour;
+  time->minute = minute;
+  time->second = second;
+
+  return TRUE;
+}
+
 /* Return time since Epoch */
 
 SilcInt64 silc_time(void)
@@ -62,14 +95,12 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time)
     return FALSE;
 
   memset(ret_time, 0, sizeof(*ret_time));
-  ret_time->year    = time->tm_year + 1900;
-  ret_time->month   = time->tm_mon + 1;
-  ret_time->day     = time->tm_mday;
-  ret_time->hour    = time->tm_hour;
-  ret_time->minute  = time->tm_min;
-  ret_time->second  = time->tm_sec;
-  ret_time->dst     = time->tm_isdst ? 1 : 0;
+  if (!silc_time_fill(ret_time, time->tm_year + 1900, time->tm_mon + 1,
+                     time->tm_mday, time->tm_hour, time->tm_min,
+                     time->tm_sec))
+    return FALSE;
 
+  ret_time->dst        = time->tm_isdst ? 1 : 0;
 #ifdef SILC_WIN32
   ret_time->utc_east   = _timezone < 0 ? 1 : 0;
   ret_time->utc_hour   = (ret_time->utc_east ? (-(_timezone)) / 3600 :
@@ -89,39 +120,6 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time)
   return TRUE;
 }
 
-/* Fills the SilcTime structure with correct values */
-
-static SilcBool silc_time_fill(SilcTime time,
-                              unsigned int year,
-                              unsigned int month,
-                              unsigned int day,
-                              unsigned int hour,
-                              unsigned int minute,
-                              unsigned int second)
-{
-  if (year > 8191)
-    return FALSE;
-  if (month < 1 || month > 12)
-    return FALSE;
-  if (day < 1 || day > 31)
-    return FALSE;
-  if (hour > 23)
-    return FALSE;
-  if (minute > 60)
-    return FALSE;
-  if (second > 61)
-    return FALSE;
-
-  time->year = year;
-  time->month = month;
-  time->day = day;
-  time->hour = hour;
-  time->minute = minute;
-  time->second = second;
-
-  return TRUE;
-}
-
 /* Returns time from universal time string into SilcTime */
 
 SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time)
index 47890ee5fc9ee660d9fc0f1dfe0f6e33a3a87c90..c5cfc8be366fc77073dc0144ec612a3142924beb 100644 (file)
@@ -45,7 +45,7 @@
  *
  ***/
 typedef struct {
-  unsigned int year       : 13;           /* Year,     0 - 8191 */
+  unsigned int year       : 15;           /* Year,     0 - 32768 */
   unsigned int month      : 4;    /* Month,    1 - 12 */
   unsigned int day        : 5;    /* Day,      1 - 31 */
   unsigned int hour       : 5;    /* Hour,     0 - 23 */
@@ -56,7 +56,6 @@ typedef struct {
   unsigned int utc_minute : 6;    /* Offset to Zulu (UTC) minutes */
   unsigned int utc_east   : 1;    /* Offset, 1 east (+), 0 west (-) */
   unsigned int dst        : 1;    /* Set if daylight saving time */
-  /* 2 bits to spare */
 } *SilcTime, SilcTimeStruct;
 /***/
 
@@ -110,7 +109,7 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time);
  * SYNOPSIS
  *
  *    SilcBool silc_time_universal(const char *universal_time,
- *                             SilcTime ret_time);
+ *                                 SilcTime ret_time);
  *
  * DESCRIPTION
  *