[PATCH] strftime: support %q to output the quarter of year
Pádraig Brady
P@draigBrady.com
Thu Nov 3 19:46:00 GMT 2016
This is already supported by gnulib.
* manual/time.texi: Document %q outputs quarter 1..4.
* time/strftime_l.c: Implement %q.
---
manual/time.texi | 6 ++++++
time/strftime_l.c | 4 ++++
2 files changed, 10 insertions(+)
diff --git a/manual/time.texi b/manual/time.texi
index 8a5f94e..f4c5f87 100644
--- a/manual/time.texi
+++ b/manual/time.texi
@@ -1510,6 +1510,12 @@ most locales @samp{AM}/@samp{PM} format is not supported, in such cases
This format is a GNU extension.
+@item %q
+Quarter of the year (@samp{1}@dots{}@samp{4}),
+with January starting the first quarter.
+
+This format is a GNU extension.
+
@item %r
The complete calendar time using the AM/PM format of the current locale.
diff --git a/time/strftime_l.c b/time/strftime_l.c
index 869e0b9..13db490 100644
--- a/time/strftime_l.c
+++ b/time/strftime_l.c
@@ -1108,6 +1108,10 @@ __strftime_internal (s, maxsize, format, tp, tzset_called ut_argument
goto underlying_strftime;
#endif
+ case L_('q'): /* GNU extension. */
+ DO_SIGNED_NUMBER (1, tp->tm_mon < -3, tp->tm_mon / 3 + 1U);
+ break;
+
case L_('R'):
subfmt = L_("%H:%M");
goto subformat;
--
2.5.5
More information about the Libc-alpha
mailing list