Skip to content
Snippets Groups Projects
Commit 60fb2d09 authored by rswindell's avatar rswindell
Browse files

Created xpTimeZone_t typedef.

Re-introduced xpTimeZone_t to isoDate/Time_t conversion functions.
parent 884da07b
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,7 @@ time_t sane_mktime(struct tm* tm)
xpDateTime_t xpDateTime_create(unsigned year, unsigned month, unsigned day
,unsigned hour, unsigned minute, float second
,int zone)
,xpTimeZone_t zone)
{
xpDateTime_t xpDateTime;
......@@ -136,6 +136,26 @@ xpDateTime_t time_to_xpDateTime(time_t time)
/* Decimal-coded ISO-8601 date/time functions */
/**********************************************/
isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t xpDateTime, isoTime_t* isoTime)
{
if(isoTime!=NULL)
*isoTime=0;
if(xpDateTime.date.year==0)
return(0);
if(isoTime!=NULL)
*isoTime=isoTime_create(xpDateTime.time.hour,xpDateTime.time.minute,xpDateTime.time.second);
return isoDate_create(xpDateTime.date.year,xpDateTime.date.month,xpDateTime.date.day);
}
xpDateTime_t isoDateTime_to_xpDateTime(isoDate_t date, isoTime_t time)
{
return xpDateTime_create(isoDate_year(date),isoDate_month(date),isoDate_day(date)
,isoTime_hour(time),isoTime_minute(time),(float)isoTime_second(time),LOCAL_UTC_DIFF);
}
isoDate_t time_to_isoDateTime(time_t time, isoTime_t* isoTime)
{
struct tm tm;
......@@ -185,7 +205,7 @@ time_t isoDateTime_to_time(isoDate_t date, isoTime_t time)
return sane_mktime(&tm);
}
BOOL isoTimeZone_parse(const char* str, int* zone)
BOOL isoTimeZone_parse(const char* str, xpTimeZone_t* zone)
{
unsigned hour=0,minute=0;
......
......@@ -62,15 +62,17 @@ typedef struct {
float second; /* supports fractional seconds */
} xpTime_t;
typedef int xpTimeZone_t;
typedef struct {
xpDate_t date;
xpTime_t time;
int zone; /* minutes +/- UTC */
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
,int zone);
,xpTimeZone_t);
xpDateTime_t xpDateTime_now(void);
time_t xpDateTime_to_time(xpDateTime_t);
xpDateTime_t time_to_xpDateTime(time_t);
......@@ -82,31 +84,37 @@ xpDateTime_t time_to_xpDateTime(time_t);
typedef ulong isoDate_t; /* CCYYMMDD (decimal) */
typedef uint 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)+(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)
#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 date, isoTime_t time);
BOOL isoTimeZone_parse(const char* str, int* zone);
xpDateTime_t isoDateTime_parse(const char* str);
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 */
/***************************************************/
#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))
#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))
xpDateTime_t isoDateTime_to_xpDateTime(isoDate_t, isoTime_t);
isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t, isoTime_t*);
/***********************************/
/* Borland DOS date/time functions */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment