Added silc_time_epoch, converting SilcTime to Epoch time value
[runtime.git] / lib / silcutil / silctime.h
index 64eb37198ffb075754fabaf2fdaf938b71999f3b..ade1e18ad52151b9667328d995b3a8941af8bd88 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 @@
 
 */
 
-/****h* silcutil/SILC Time Interface
+/****h* silcutil/Time Interface
  *
  * DESCRIPTION
  *
@@ -30,7 +30,7 @@
 #ifndef SILCTIME_H
 #define SILCTIME_H
 
-/****s* silcutil/SilcTimeAPI/SilcTime
+/****s* silcutil/SilcTime
  *
  * NAME
  *
@@ -43,8 +43,8 @@
  *
  * SOURCE
  *
- ***/
-typedef struct {
+ */
+typedef struct SilcTimeObject {
   unsigned int year       : 15;           /* Year,     0 - 32768 */
   unsigned int month      : 4;    /* Month,    1 - 12 */
   unsigned int day        : 5;    /* Day,      1 - 31 */
@@ -59,7 +59,20 @@ typedef struct {
 } *SilcTime, SilcTimeStruct;
 /***/
 
-/****f* silcutil/SilcTimeAPI/silc_time
+/****s* silcutil/SilcTimeStruct
+ *
+ * NAME
+ *
+ *    typedef struct { ... } *SilcTime, SilcTimeStruct;
+ *
+ * DESCRIPTION
+ *
+ *    This context represents time value.  It includes date and time
+ *    down to millisecond precision.  The structure size is 64 bits.
+ *
+ ***/
+
+/****f* silcutil/silc_time
  *
  * SYNOPSIS
  *
@@ -73,7 +86,7 @@ typedef struct {
  ***/
 SilcInt64 silc_time(void);
 
-/****f* silcutil/SilcTimeAPI/silc_time_msec
+/****f* silcutil/silc_time_msec
  *
  * SYNOPSIS
  *
@@ -87,7 +100,7 @@ SilcInt64 silc_time(void);
  ***/
 SilcInt64 silc_time_msec(void);
 
-/****f* silcutil/SilcTimeAPI/silc_time_usec
+/****f* silcutil/silc_time_usec
  *
  * SYNOPSIS
  *
@@ -101,7 +114,7 @@ SilcInt64 silc_time_msec(void);
  ***/
 SilcInt64 silc_time_usec(void);
 
-/****f* silcutil/SilcTimeAPI/silc_time_string
+/****f* silcutil/silc_time_string
  *
  * SYNOPSIS
  *
@@ -118,11 +131,11 @@ SilcInt64 silc_time_usec(void);
  ***/
 const char *silc_time_string(SilcInt64 time_val_sec);
 
-/****f* silcutil/SilcTimeAPI/silc_time_value
+/****f* silcutil/silc_time_value
  *
  * SYNOPSIS
  *
- *   SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
+ *    SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
  *
  * DESCRIPTION
  *
@@ -134,7 +147,21 @@ const char *silc_time_string(SilcInt64 time_val_sec);
  ***/
 SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
 
-/****f* silcutil/SilcTimeAPI/silc_timezone
+/****f* silcutil/silc_time_value
+ *
+ * SYNOPSIS
+ *
+ *    SilcUInt64 silc_time_epoch(SilcTime timeval);
+ *
+ * DESCRIPTION
+ *
+ *    Converts SilcTime into Epoch time value and returns the converted
+ *    value.
+ *
+ ***/
+SilcUInt64 silc_time_epoch(SilcTime timeval);
+
+/****f* silcutil/silc_timezone
  *
  * SYNOPSIS
  *
@@ -153,7 +180,7 @@ SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
  ***/
 SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size);
 
-/****f* silcutil/SilcTimeAPI/silc_time_universal
+/****f* silcutil/silc_time_universal
  *
  * SYNOPSIS
  *
@@ -179,7 +206,7 @@ SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size);
  ***/
 SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time);
 
-/****f* silcutil/SilcTimeAPI/silc_time_universal_string
+/****f* silcutil/silc_time_universal_string
  *
  * SYNOPSIS
  *
@@ -195,7 +222,7 @@ SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time);
 SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string,
                                    SilcUInt32 ret_string_size);
 
-/****f* silcutil/SilcTimeAPI/silc_time_generalized
+/****f* silcutil/silc_time_generalized
  *
  * SYNOPSIS
  *
@@ -226,7 +253,7 @@ SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string,
 SilcBool
 silc_time_generalized(const char *generalized_time, SilcTime ret_time);
 
-/****f* silcutil/SilcTimeAPI/silc_time_generalized_string
+/****f* silcutil/silc_time_generalized_string
  *
  * SYNOPSIS
  *
@@ -243,7 +270,7 @@ silc_time_generalized(const char *generalized_time, SilcTime ret_time);
 SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string,
                                      SilcUInt32 ret_string_size);
 
-/****f* silcutil/SilcTimeAPI/silc_compare_timeval
+/****f* silcutil/silc_compare_timeval
  *
  * SYNOPSIS
  *
@@ -251,14 +278,14 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string,
  *
  * DESCRIPTION
  *
- *    Compares `t1' and `t2' time structures and returns less than zero, 
+ *    Compares `t1' and `t2' time structures and returns less than zero,
  *    zero or more than zero when `t1' is smaller, equal or bigger than
  *    `t2', respectively.
  *
  ***/
 int silc_compare_timeval(struct timeval *t1, struct timeval *t2);
 
-/****f* silcutil/SilcTimeAPI/silc_gettimeofday
+/****f* silcutil/silc_gettimeofday
  *
  * SYNOPSIS
  *
@@ -272,47 +299,4 @@ int silc_compare_timeval(struct timeval *t1, struct timeval *t2);
  ***/
 int silc_gettimeofday(struct timeval *p);
 
-/****f* silcutil/SilcTimeAPI/silc_usleep
- *
- * SYNOPSIS
- *
- *    void silc_usleep(long microseconds);
- *
- * DESCRIPTION
- *
- *    Delays the execution of process/thread for the specified amount of
- *    time, which is in microseconds.
- *
- * NOTES
- *
- *    The delay is only approximate and on some platforms the resolution is
- *    in fact milliseconds.
- *
- ***/
-static inline
-void silc_usleep(long microseconds)
-{
-#ifdef SILC_UNIX
-#ifdef HAVE_NANOSLEEP
-  struct timespec tv;
-  tv.tv_sec = 0;
-  tv.tv_nsec = microseconds * 1000;
-#endif /* HAVE_NANOSLEEP */
-#endif /* SILC_UNIX */
-
-#ifdef SILC_UNIX
-#ifdef HAVE_NANOSLEEP
-  nanosleep(&tv, NULL);
-#else
-  usleep(microseconds);
-#endif /* HAVE_NANOSLEEP */
-#endif /* SILC_UNIX */
-#ifdef SILC_WIN32
-  Sleep(microseconds / 1000);
-#endif /* SILC_WIN32 */
-#ifdef SILC_SYMBIAN
-  silc_symbian_usleep(microseconds);
-#endif /* SILC_SYMBIAN */
-}
-
 #endif /* SILCTIME_H */