#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)
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 :
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)
*
***/
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 */
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;
/***/
* SYNOPSIS
*
* SilcBool silc_time_universal(const char *universal_time,
- * SilcTime ret_time);
+ * SilcTime ret_time);
*
* DESCRIPTION
*