From: Elvira Khabirova <lineprinter0@gmail.com>
Date: Sat, 13 Aug 2016 17:27:38 +0000 (+0300)
Subject: Make date output format conform to ISO 8601
X-Git-Tag: v4.15~58
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ad53524377b326da800274d86cbd838d15dfa354;p=strace

Make date output format conform to ISO 8601

* util.c (sprinttime): Make date output conform to ISO 8601.
* tests/utime.c (print_tm): Update expected output.
* tests/xstatx.c (print_time): Likewise.
---

diff --git a/tests/utime.c b/tests/utime.c
index fdb48a70..b81256c8 100644
--- a/tests/utime.c
+++ b/tests/utime.c
@@ -42,9 +42,11 @@
 static void
 print_tm(const struct tm * const p)
 {
-	printf("%02d/%02d/%02d-%02d:%02d:%02d",
-	       p->tm_year + 1900, p->tm_mon + 1, p->tm_mday,
-	       p->tm_hour, p->tm_min, p->tm_sec);
+	char buf[256];
+
+	strftime(buf, sizeof(buf), "%FT%T%z", p);
+
+	printf("%s", buf);
 }
 
 static long
diff --git a/tests/xstatx.c b/tests/xstatx.c
index 12da191c..64204647 100644
--- a/tests/xstatx.c
+++ b/tests/xstatx.c
@@ -57,12 +57,15 @@ print_time(const time_t t)
 
 	struct tm *p = localtime(&t);
 
-	if (p)
-		printf("%02d/%02d/%02d-%02d:%02d:%02d",
-		       p->tm_year + 1900, p->tm_mon + 1, p->tm_mday,
-		       p->tm_hour, p->tm_min, p->tm_sec);
-	else
+	if (p) {
+		char buf[256];
+
+		strftime(buf, sizeof(buf), "%FT%T%z", p);
+
+		printf("%s", buf);
+	} else {
 		printf("%llu", zero_extend_signed_to_ull(t));
+	}
 }
 
 # ifndef STRUCT_STAT
diff --git a/util.c b/util.c
index 3fa3de31..a3c505d6 100644
--- a/util.c
+++ b/util.c
@@ -524,7 +524,7 @@ const char *
 sprinttime(time_t t)
 {
 	struct tm *tmp;
-	static char buf[sizeof(int) * 3 * 6];
+	static char buf[sizeof(int) * 3 * 6 + sizeof("+0000")];
 
 	if (t == 0) {
 		strcpy(buf, "0");
@@ -532,11 +532,9 @@ sprinttime(time_t t)
 	}
 	tmp = localtime(&t);
 	if (tmp)
-		snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
-			tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
-			tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+		strftime(buf, sizeof(buf), "%FT%T%z", tmp);
 	else
-		snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
+		snprintf(buf, sizeof(buf), "%lu", (unsigned long) t);
 
 	return buf;
 }