Added silc_time_epoch, converting SilcTime to Epoch time value
[runtime.git] / lib / silcutil / silctime.h
index c5cfc8be366fc77073dc0144ec612a3142924beb..ade1e18ad52151b9667328d995b3a8941af8bd88 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2005 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
  *
  * DESCRIPTION
  *
  *    This context represents time value.  It includes date and time
- *    down to millisecond precision.
+ *    down to millisecond precision.  The structure size is 64 bits.
  *
  * 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,38 +86,101 @@ typedef struct {
  ***/
 SilcInt64 silc_time(void);
 
-/****f* silcutil/SilcTimeAPI/silc_time_string
+/****f* silcutil/silc_time_msec
+ *
+ * SYNOPSIS
+ *
+ *    SilcInt64 silc_time_msec(void);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the current time of the system since Epoch in millisecond
+ *    resolution.  Returns - 1 on error.
+ *
+ ***/
+SilcInt64 silc_time_msec(void);
+
+/****f* silcutil/silc_time_usec
  *
  * SYNOPSIS
  *
- *    const char *silc_time_string(SilcInt64 timeval);
+ *    SilcInt64 silc_time_usec(void);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the current time of the system since Epoch in microsecond
+ *    resolution.  Returns - 1 on error.
+ *
+ ***/
+SilcInt64 silc_time_usec(void);
+
+/****f* silcutil/silc_time_string
+ *
+ * SYNOPSIS
+ *
+ *    const char *silc_time_string(SilcInt64 time_val_sec);
  *
  * DESCRIPTION
  *
  *    Returns time and date as string.  The caller must not free the string
  *    and next call to this function will delete the old string.  If the
- *    `timeval' is zero (0) returns current time as string, otherwise the
- *    `timeval' as string.  Returns NULL on error.
+ *    `time_val_sec' is zero (0) returns current time as string, otherwise the
+ *    `time_val_sec' as string.  The `time_val_sec' is in seconds since Epoch.
+ *    Returns NULL on error.
  *
  ***/
-const char *silc_time_string(SilcInt64 timeval);
+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 timeval, SilcTime ret_time);
+ *    SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
  *
  * DESCRIPTION
  *
- *    Returns time and date as SilcTime.  If the `timeval' is zero (0)
- *    returns current time as SilcTime, otherwise the `timeval' as SilcTime.
+ *    Returns time and date as SilcTime.  If the `time_val_msec' is zero (0)
+ *    returns current time as SilcTime, otherwise the `time_val_msec' as
+ *    SilcTime.  The `time_val_msec' is in milliseconds since Epoch.  Returns
+ *    FALSE on error, TRUE otherwise.
+ *
+ ***/
+SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time);
+
+/****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
+ *
+ *    SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size);
+ *
+ * DESCRIPTION
+ *
+ *    Returns current timezone in Universal time format into the `timezone'
+ *    buffer of size of `timezone_size'.  The possible values this function
+ *    returns are: Z (For UTC timezone), +hh (UTC + hours) -hh (UTC - hours),
+ *    +hh:mm (UTC + hours:minutes) or -hh:mm (UTC - hours:minutes).  The
+ *    returned values are always offsets to UTC.
+ *
  *    Returns FALSE on error, TRUE otherwise.
  *
  ***/
-SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time);
+SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size);
 
-/****f* silcutil/SilcTimeAPI/silc_time_universal
+/****f* silcutil/silc_time_universal
  *
  * SYNOPSIS
  *
@@ -130,11 +206,11 @@ SilcBool silc_time_value(SilcInt64 timeval, SilcTime ret_time);
  ***/
 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
  *
- *    SilcBool silc_time_universal_string(SilcTime timeval, char *ret_string,
+ *    SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string,
  *                                        SilcUInt32 ret_string_size);
  *
  * DESCRIPTION
@@ -143,10 +219,10 @@ SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time);
  *    `ret_string' buffer.  Returns FALSE if the buffer is too small.
  *
  ***/
-SilcBool silc_time_universal_string(SilcTime timeval, char *ret_string,
+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
  *
@@ -177,11 +253,12 @@ SilcBool silc_time_universal_string(SilcTime timeval, 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
  *
- *    SilcBool silc_time_generalized_string(SilcTime timeval, char *ret_string,
+ *    SilcBool silc_time_generalized_string(SilcTime time_val,
+ *                                          char *ret_string,
  *                                          SilcUInt32 ret_string_size);
  *
  * DESCRIPTION
@@ -190,7 +267,36 @@ silc_time_generalized(const char *generalized_time, SilcTime ret_time);
  *    `ret_string' buffer.  Returns FALSE if the buffer is too small.
  *
  ***/
-SilcBool silc_time_generalized_string(SilcTime timeval, char *ret_string,
+SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string,
                                      SilcUInt32 ret_string_size);
 
+/****f* silcutil/silc_compare_timeval
+ *
+ * SYNOPSIS
+ *
+ *    int silc_compare_timeval(struct time_val *t1, struct time_val *t2);
+ *
+ * DESCRIPTION
+ *
+ *    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/silc_gettimeofday
+ *
+ * SYNOPSIS
+ *
+ *    int silc_gettimeofday(struct timeval *p);
+ *
+ * DESCRIPTION
+ *
+ *    Return current time to struct timeval.  This function is system
+ *    dependant.  Returns 0 on success and -1 on error.
+ *
+ ***/
+int silc_gettimeofday(struct timeval *p);
+
 #endif /* SILCTIME_H */