On 06/10/16 12:53, Pádraig Brady wrote:
> On 06/10/16 11:11, john woods wrote:
>> date +%YW%V gives week and year; it would be nice if date +%YQ%q could
>> return, eg 2016Q3 as having a quarters code in date would save AWKwardness
>> or shell arithmetic.
>>
>> Perhaps we could have
>> %q 1,2,3,4

> This is one of those marginal calls.
> 
> It's not that awkward to get the quarter number: $(( ($(date +%-m)-1)/3+1 ))
> But I agree it would be useful to give the number directly.

> Note perl Date::Format uses %q to give the quarter number, starting with 1

Attached in the gnulib portion.

I'll suggest for inclusion to glibc also.

thanks,
Pádraig
>From d26da1df7498be73daa865816485118e17b8f764 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <pbr...@fb.com>
Date: Wed, 19 Oct 2016 14:46:14 -0700
Subject: [PATCH] strftime: support %q to return the quarter

---
 lib/strftime.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/strftime.c b/lib/strftime.c
index 4e65190..564e819 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -1115,6 +1115,10 @@ strftime_case_ (bool upcase, STREAM_OR_CHAR_T *s,
           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

Reply via email to