From e4c7c15dcc59d2e61881fb823d752254b913094f Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 23 Feb 2008 21:05:30 +0000
Subject: [PATCH] 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.

---
 src/xpdev/xpdatetime.c | 30 +++++++++++++++++++++++-------
 src/xpdev/xpdatetime.h | 11 +++++++++++
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/xpdev/xpdatetime.c b/src/xpdev/xpdatetime.c
index 694c9875c2..e4251955ff 100644
--- a/src/xpdev/xpdatetime.c
+++ b/src/xpdev/xpdatetime.c
@@ -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;
 }
diff --git a/src/xpdev/xpdatetime.h b/src/xpdev/xpdatetime.h
index 360423f781..61ce9fdb3a 100644
--- a/src/xpdev/xpdatetime.h
+++ b/src/xpdev/xpdatetime.h
@@ -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);
-- 
GitLab