* util.c (sprinttime): Make date output conform to ISO 8601.
* tests/utime.c (print_tm): Update expected output.
* tests/xstatx.c (print_time): Likewise.
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
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
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");
}
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;
}