Skip to content
Snippets Groups Projects
Commit 5c2e22ca authored by rswindell's avatar rswindell
Browse files

Don't overload time() with time argument name.

Use ZERO_VAR instead of memset().
parent 1186deef
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2008 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2009 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 *
......@@ -122,15 +122,14 @@ time_t xpDateTime_to_time(xpDateTime_t xpDateTime)
return sane_mktime(&tm);
}
xpDateTime_t time_to_xpDateTime(time_t time, xpTimeZone_t zone)
xpDateTime_t time_to_xpDateTime(time_t ti, xpTimeZone_t zone)
{
xpDateTime_t never;
struct tm tm;
memset(&never,0,sizeof(never));
ZERO_VAR(never);
ZERO_VAR(tm);
if(localtime_r(&time,&tm)==NULL)
if(localtime_r(&ti,&tm)==NULL)
return(never);
return xpDateTime_create(1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday
......@@ -143,8 +142,7 @@ xpDateTime_t gmtime_to_xpDateTime(time_t ti)
xpDateTime_t never;
struct tm tm;
memset(&never,0,sizeof(never));
ZERO_VAR(never);
ZERO_VAR(tm);
if(gmtime_r(&ti,&tm)==NULL)
return(never);
......@@ -230,7 +228,7 @@ isoTime_t gmtime_to_isoTime(time_t ti)
return isoTime;
}
time_t isoDateTime_to_time(isoDate_t date, isoTime_t time)
time_t isoDateTime_to_time(isoDate_t date, isoTime_t ti)
{
struct tm tm;
......@@ -243,9 +241,9 @@ time_t isoDateTime_to_time(isoDate_t date, isoTime_t time)
tm.tm_mon = isoDate_month(date);
tm.tm_mday = isoDate_day(date);
tm.tm_hour = isoTime_hour(time);
tm.tm_min = isoTime_minute(time);
tm.tm_sec = isoTime_second(time);
tm.tm_hour = isoTime_hour(ti);
tm.tm_min = isoTime_minute(ti);
tm.tm_sec = isoTime_second(ti);
return sane_mktime(&tm);
}
......@@ -275,26 +273,26 @@ char* xpDate_to_isoDateStr(xpDate_t date, const char* sep, char* str, size_t max
* 2 "14.02:39.82"
* 3 "14.02:39.829"
*/
char* xpTime_to_isoTimeStr(xpTime_t time, const char* sep, int precision
char* xpTime_to_isoTimeStr(xpTime_t ti, const char* sep, int precision
,char* str, size_t maxlen)
{
if(sep==NULL)
sep=":";
if(precision < -1) /* HH */
snprintf(str, maxlen, "%02lu", time.hour);
snprintf(str, maxlen, "%02lu", ti.hour);
else if(precision < 0) /* HH:MM */
snprintf(str, maxlen, "%02lu%s%02lu"
,time.hour ,sep
,time.minute
,ti.hour ,sep
,ti.minute
);
else /* HH:MM:SS[.fract] */
snprintf(str, maxlen, "%02lu%s%02lu%s%0*.*f"
,time.hour ,sep
,time.minute ,sep
,ti.hour ,sep
,ti.minute ,sep
,precision ? (precision+3) : 2
,precision
,time.second
,ti.second
);
return str;
......
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