--- sbbs/src/xpdev/datewrap.h 2018/04/24 16:41:24 1.1.1.1 +++ sbbs/src/xpdev/datewrap.h 2018/04/24 16:45:26 1.1.1.2 @@ -1,14 +1,14 @@ /* datewrap.h */ -/* Wrappers for Borland getdate() and gettime() functions */ +/* Wrappers for non-standard date and time functions */ -/* $Id: datewrap.h,v 1.1.1.1 2018/04/24 16:41:24 root Exp $ */ +/* $Id: datewrap.h,v 1.1.1.2 2018/04/24 16:45:26 root Exp $ */ /**************************************************************************** * @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * * - * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html * + * Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * @@ -40,79 +40,31 @@ #include "genwrap.h" /* time_t */ -/* Compensates for struct tm "weirdness" */ -time_t sane_mktime(struct tm*); +#if defined(__cplusplus) +extern "C" { +#endif + +/* Return difference (in seconds) in time() result from standard (0 on success) */ +time_t checktime(void); + +/* Implementation of mktime() that handles common tm element conversions for you */ +time_t sane_mktime(struct tm* tm); -/**************************************/ -/* Cross-platform date/time functions */ -/**************************************/ - -typedef struct { - unsigned year; - unsigned month; - unsigned day; -} xpDate_t; - -typedef struct { - unsigned hour; - unsigned minute; - float second; /* supports fractional seconds */ -} xpTime_t; - -typedef int xpTimeZone_t; - -typedef struct { - xpDate_t date; - xpTime_t time; - xpTimeZone_t zone; /* minutes +/- UTC */ -} xpDateTime_t; - -xpDateTime_t xpDateTime_create(unsigned year, unsigned month, unsigned day - ,unsigned hour, unsigned minute, float second - ,xpTimeZone_t); -xpDateTime_t xpDateTime_now(void); -time_t xpDateTime_to_time(xpDateTime_t); -xpDateTime_t time_to_xpDateTime(time_t); -xpTimeZone_t xpTimeZone_local(void); - -/**********************************************/ -/* Decimal-coded ISO-8601 date/time functions */ -/**********************************************/ - -typedef ulong isoDate_t; /* CCYYMMDD (decimal) */ -typedef ulong isoTime_t; /* HHMMSS (decimal) */ - -#define isoDate_create(year,mon,day) (((year)*10000)+((mon)*100)+(day)) -#define isoTime_create(hour,min,sec) (((hour)*10000)+((min)*100)+((unsigned)sec)) - -#define isoDate_year(date) ((date)/10000) -#define isoDate_month(date) (((date)/100)%100) -#define isoDate_day(date) ((date)%100) - -#define isoTime_hour(time) ((time)/10000) -#define isoTime_minute(time) (((time)/100)%100) -#define isoTime_second(time) ((time)%100) - -BOOL isoTimeZone_parse(const char* str, xpTimeZone_t*); -xpDateTime_t isoDateTime_parse(const char* str); - -/**********************************************/ -/* Conversion between time_t and isoDate/Time */ -/**********************************************/ -isoTime_t time_to_isoTime(time_t); -isoDate_t time_to_isoDateTime(time_t, isoTime_t*); -time_t isoDateTime_to_time(isoDate_t, isoTime_t); -#define time_to_isoDate(t) time_to_isoDateTime(t,NULL) - -/***************************************************/ -/* Conversion between xpDate/Time and isoDate/Time */ -/***************************************************/ +/*********************************************************************************/ +/* Win32 implementations of recursive (thread-safe) std C time functions on Unix */ +/*********************************************************************************/ -#define xpDate_to_isoDate(date) isoDate_create((date).year,(date).month,(date).day) -#define xpTime_to_isoTime(time) isoTime_create((time).hour,(time).minute,(unsigned)((time).second)) +#if !defined(__unix__) -xpDateTime_t isoDateTime_to_xpDateTime(isoDate_t, isoTime_t); -isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t, isoTime_t*); + #include /* time_t, etc. */ + + DLLEXPORT struct tm* DLLCALL gmtime_r(const time_t* t, struct tm* tm); + DLLEXPORT struct tm* DLLCALL localtime_r(const time_t* t, struct tm* tm); + DLLEXPORT char* DLLCALL ctime_r(const time_t *t, char *buf); + DLLEXPORT char* DLLCALL asctime_r(const struct tm *tm, char *buf); + DLLEXPORT char* DLLCALL strtok_r(char *str, const char *delim, char **last); + +#endif /***********************************/ /* Borland DOS date/time functions */ @@ -137,19 +89,14 @@ struct time { unsigned char ti_sec; }; -#if defined(__cplusplus) -extern "C" { -#endif - #define getdate(x) xp_getdate(x) void xp_getdate(struct date*); void gettime(struct time*); +#endif /* !Borland */ + #if defined(__cplusplus) } #endif -#endif /* !Borland */ - #endif /* Don't add anything after this line */ -