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

xpTime_to_isoTimeStr() and the functions that call it, now support precision

argument values of -1 (for no seconds) and < -1 (for no minutes or seconds) in
the output string.
parent 5d7d6ba0
Branches
Tags
No related merge requests found
......@@ -267,19 +267,35 @@ char* xpDate_to_isoDateStr(xpDate_t date, const char* sep, char* str, size_t max
return str;
}
/* precision example output
* -2 "14"
* -1 "14:02"
* 0 "14:02:39"
* 1 "14.02:39.8"
* 2 "14.02:39.82"
* 3 "14.02:39.829"
*/
char* xpTime_to_isoTimeStr(xpTime_t time, const char* sep, int precision
,char* str, size_t maxlen)
{
if(sep==NULL)
sep=":";
snprintf(str, maxlen, "%02lu%s%02lu%s%0*.*f"
,time.hour ,sep
,time.minute ,sep
,precision ? (precision+3) : 2
,precision
,time.second
);
if(precision < -1) /* HH */
snprintf(str, maxlen, "%02lu", time.hour);
else if(precision < 0) /* HH:MM */
snprintf(str, maxlen, "%02lu%s%02lu"
,time.hour ,sep
,time.minute
);
else /* HH:MM:SS[.fract] */
snprintf(str, maxlen, "%02lu%s%02lu%s%0*.*f"
,time.hour ,sep
,time.minute ,sep
,precision ? (precision+3) : 2
,precision
,time.second
);
return str;
}
......
......@@ -126,6 +126,17 @@ isoDate_t xpDateTime_to_isoDateTime(xpDateTime_t, isoTime_t*);
/*****************************************************************/
/* Conversion from xpDate/Time/Zone to isoDate/Time/Zone Strings */
/*****************************************************************/
/* NULL sep (separator) values are automatically replaced with ISO-standard separators */
/* precision example output
* -2 "14"
* -1 "14:02"
* 0 "14:02:39"
* 1 "14.02:39.8"
* 2 "14.02:39.82"
* 3 "14.02:39.829"
*/
char* xpDate_to_isoDateStr(xpDate_t
,const char* sep
,char* str, size_t maxlen);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment