Added silc_time_epoch, converting SilcTime to Epoch time value
[runtime.git] / lib / silcutil / silctime.c
index 4dc7f2172ec5470d0a78ff4736aefa5e38d2ffba..c17f08d27692e6e6ea1a9b537fa275b88a464b73 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2007 Pekka Riikonen
+  Copyright (C) 2003 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 
 */
 
-#include "silc.h"
+#include "silcruntime.h"
 
 /* Fills the SilcTime structure with correct values */
 
@@ -173,6 +173,26 @@ SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time)
   return TRUE;
 }
 
+/* SilcTime to epoch */
+
+SilcUInt64 silc_time_epoch(SilcTime timeval)
+{
+  struct tm val;
+
+  if (!timeval)
+    return 0;
+
+  val.tm_sec = timeval->second;
+  val.tm_min = timeval->minute;
+  val.tm_hour = timeval->hour;
+  val.tm_mday = timeval->day;
+  val.tm_mon = timeval->month - 1;
+  val.tm_year = timeval->year - 1900;
+  val.tm_isdst = timeval->dst;
+
+  return (SilcUInt64)mktime(&val);
+}
+
 /* Returns timezone */
 
 SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size)