From 16a0d47fdce2bd6a2c7d63c97fca28b6ba4e3d9b Mon Sep 17 00:00:00 2001
From: Tavian Barnes <tavianator@tavianator.com>
Date: Tue, 24 Jul 2018 19:34:46 -0400
Subject: printf: Support all standard strftime() directives

---
 printf.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/printf.c b/printf.c
index d57c570..0a969d8 100644
--- a/printf.c
+++ b/printf.c
@@ -149,15 +149,6 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf_directive *di
 	case '@':
 		ret = snprintf(buf, sizeof(buf), "%lld.%09ld0", (long long)ts->tv_sec, (long)ts->tv_nsec);
 		break;
-	case 'k':
-		ret = snprintf(buf, sizeof(buf), "%2d", tm.tm_hour);
-		break;
-	case 'l':
-		ret = snprintf(buf, sizeof(buf), "%2d", (tm.tm_hour + 11)%12 + 1);
-		break;
-	case 'S':
-		ret = snprintf(buf, sizeof(buf), "%.2d.%09ld0", tm.tm_sec, (long)ts->tv_nsec);
-		break;
 	case '+':
 		ret = snprintf(buf, sizeof(buf), "%4d-%.2d-%.2d+%.2d:%.2d:%.2d.%09ld0",
 		               1900 + tm.tm_year,
@@ -168,6 +159,25 @@ static int bfs_printf_strftime(FILE *file, const struct bfs_printf_directive *di
 		               tm.tm_sec,
 		               (long)ts->tv_nsec);
 		break;
+	case 'k':
+		ret = snprintf(buf, sizeof(buf), "%2d", tm.tm_hour);
+		break;
+	case 'l':
+		ret = snprintf(buf, sizeof(buf), "%2d", (tm.tm_hour + 11)%12 + 1);
+		break;
+	case 's':
+		ret = snprintf(buf, sizeof(buf), "%lld", (long long)ts->tv_sec);
+		break;
+	case 'S':
+		ret = snprintf(buf, sizeof(buf), "%.2d.%09ld0", tm.tm_sec, (long)ts->tv_nsec);
+		break;
+	case 'T':
+		ret = snprintf(buf, sizeof(buf), "%.2d:%.2d:%.2d.%09ld0",
+			       tm.tm_hour,
+			       tm.tm_min,
+			       tm.tm_sec,
+			       (long)ts->tv_nsec);
+		break;
 
 	// POSIX strftime() features
 	default:
@@ -754,7 +764,7 @@ struct bfs_printf *parse_bfs_printf(const char *format, struct cmdline *cmdline)
 					cfprintf(cerr, "%{er}error: '%s': Incomplete time specifier '%s%c'.%{rs}\n",
 					         format, directive->str, i[-1]);
 					goto directive_error;
-				} else if (strchr("@HIklMprST+XZaAbBcdDhjmUwWxyY", c)) {
+				} else if (strchr("%+@aAbBcCdDeFgGhHIjklmMnprRsStTuUVwWxXyYzZ", c)) {
 					directive->c = c;
 				} else {
 					cfprintf(cerr, "%{er}error: '%s': Unrecognized time specifier '%%%c%c'.%{rs}\n",
-- 
cgit v1.2.3