5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2003 - 2006 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 /****h* silcutil/SILC Time Interface
24 * This interface provides various utility functions for getting current
25 * time and converting different time representations into the SilcTime
33 /****s* silcutil/SilcTimeAPI/SilcTime
37 * typedef struct { ... } *SilcTime, SilcTimeStruct;
41 * This context represents time value. It includes date and time
42 * down to millisecond precision. The structure size is 64 bits.
48 unsigned int year : 15; /* Year, 0 - 32768 */
49 unsigned int month : 4; /* Month, 1 - 12 */
50 unsigned int day : 5; /* Day, 1 - 31 */
51 unsigned int hour : 5; /* Hour, 0 - 23 */
52 unsigned int minute : 6; /* Minute, 0 - 59 */
53 unsigned int second : 6; /* Second, 0 - 61 */
54 unsigned int msecond : 10; /* Millisec, 0 - 1000 */
55 unsigned int utc_hour : 5; /* Offset to Zulu (UTC) hours */
56 unsigned int utc_minute : 6; /* Offset to Zulu (UTC) minutes */
57 unsigned int utc_east : 1; /* Offset, 1 east (+), 0 west (-) */
58 unsigned int dst : 1; /* Set if daylight saving time */
59 } *SilcTime, SilcTimeStruct;
62 /****f* silcutil/SilcTimeAPI/silc_time
66 * SilcInt64 silc_time(void);
70 * Returns the current time of the system since Epoch. The returned
71 * value is seconds since Epoch (1.1.1970). Returns -1 on error.
74 SilcInt64 silc_time(void);
76 /****f* silcutil/SilcTimeAPI/silc_time_msec
80 * SilcInt64 silc_time_msec(void);
84 * Returns the current time of the system since Epoch in millisecond
85 * resolution. Returns - 1 on error.
88 SilcInt64 silc_time_msec(void);
90 /****f* silcutil/SilcTimeAPI/silc_time_usec
94 * SilcInt64 silc_time_usec(void);
98 * Returns the current time of the system since Epoch in microsecond
99 * resolution. Returns - 1 on error.
102 SilcInt64 silc_time_usec(void);
104 /****f* silcutil/SilcTimeAPI/silc_time_string
108 * const char *silc_time_string(SilcInt64 time_val);
112 * Returns time and date as string. The caller must not free the string
113 * and next call to this function will delete the old string. If the
114 * `time_val' is zero (0) returns current time as string, otherwise the
115 * `time_val' as string. The `time_val' is in seconds since Epoch.
116 * Returns NULL on error.
119 const char *silc_time_string(SilcInt64 time_val);
121 /****f* silcutil/SilcTimeAPI/silc_time_value
125 * SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time);
129 * Returns time and date as SilcTime. If the `time_val' is zero (0)
130 * returns current time as SilcTime, otherwise the `time_val' as SilcTime.
131 * The `time_val' is in milliseconds since Epoch. Returns FALSE on error,
135 SilcBool silc_time_value(SilcInt64 time_val, SilcTime ret_time);
137 /****f* silcutil/SilcTimeAPI/silc_time_universal
141 * SilcBool silc_time_universal(const char *universal_time,
142 * SilcTime ret_time);
146 * Returns time and date as SilcTime from `universal_time' string which
147 * format is "YYMMDDhhmmssZ", where YY is year, MM is month, DD is day,
148 * hh is hour, mm is minutes, ss is seconds and Z is timezone, which
149 * by default is Zulu (UTC). Universal time is defined in ISO/EIC 8824-1.
151 * Returns FALSE on error, TRUE otherwise.
155 * SilcTimeStruct ret_time;
157 * time is 03/02/19 19:04:03 Zulu (UTC)
158 * silc_time_universal("030219190403Z", &ret_time);
161 SilcBool silc_time_universal(const char *universal_time, SilcTime ret_time);
163 /****f* silcutil/SilcTimeAPI/silc_time_universal_string
167 * SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string,
168 * SilcUInt32 ret_string_size);
172 * Encodes the SilcTime `time' into the universal time format into the
173 * `ret_string' buffer. Returns FALSE if the buffer is too small.
176 SilcBool silc_time_universal_string(SilcTime time_val, char *ret_string,
177 SilcUInt32 ret_string_size);
179 /****f* silcutil/SilcTimeAPI/silc_time_generalized
183 * SilcBool silc_time_generalized(const char *generalized_time,
184 * SilcTime ret_time);
188 * Returns time and date as SilcTime from `generalized_time' string which
189 * format is "YYYYMMDDhhmmss.ppZ", where YYYY is year, MM is month, DD
190 * is day, hh is hour, mm is minutes, ss is seconds which may have optional
191 * precision pp, and Z is timezone, which by default is Zulu (UTC).
192 * Generalized time is defined in ISO/EIC 8824-1.
194 * Returns FALSE on error, TRUE otherwise.
198 * SilcTimeStruct ret_time;
200 * time is 2003/02/19 19:04:03 Zulu (UTC)
201 * silc_time_generalized("20030219190403Z", &ret_time);
203 * time is 2003/02/19 19:05:10.212 Zulu (UTC)
204 * silc_time_generalized("20030219190510.212Z", &ret_time);
208 silc_time_generalized(const char *generalized_time, SilcTime ret_time);
210 /****f* silcutil/SilcTimeAPI/silc_time_generalized_string
214 * SilcBool silc_time_generalized_string(SilcTime time_val,
216 * SilcUInt32 ret_string_size);
220 * Encodes the SilcTime `time' into the generalized time format into the
221 * `ret_string' buffer. Returns FALSE if the buffer is too small.
224 SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string,
225 SilcUInt32 ret_string_size);
227 /****f* silcutil/SilcTimeAPI/silc_compare_timeval
231 * SilcBool silc_compare_timeval(struct time_val *smaller,
232 * struct time_val *bigger)
236 * Compare two timeval structures and return TRUE if the first
237 * time value is smaller than the second time value.
240 SilcBool silc_compare_timeval(struct timeval *smaller,
241 struct timeval *bigger);
243 /****f* silcutil/SilcTimeAPI/silc_gettimeofday
247 * int silc_gettimeofday(struct timeval *p);
251 * Return current time to struct timeval. This function is system
252 * dependant. Returns 0 on success and -1 on error.
255 int silc_gettimeofday(struct timeval *p);
257 #endif /* SILCTIME_H */