strftime: support %q to output the quarter of year

Message ID 1478202401-5238-1-git-send-email-P@draigBrady.com
State New, archived
Headers

Commit Message

Pádraig Brady Nov. 3, 2016, 7:46 p.m. UTC
  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(+)
  

Comments

Florian Weimer Nov. 3, 2016, 7:58 p.m. UTC | #1
* Pádraig Brady:

> This is already supported by gnulib.

This needs a test case (at least a test case update).

> +        case L_('q'):           /* GNU extension.  */
> +          DO_SIGNED_NUMBER (1, tp->tm_mon < -3, tp->tm_mon / 3 + 1U);
> +          break;

I don't think we have DO_SIGNED_NUMBER in glibc.
  
Adhemerval Zanella Netto Nov. 3, 2016, 8:28 p.m. UTC | #2
On 03/11/2016 17:58, Florian Weimer wrote:
> * Pádraig Brady:
> 
>> This is already supported by gnulib.
> 
> This needs a test case (at least a test case update).
> 
>> +        case L_('q'):           /* GNU extension.  */
>> +          DO_SIGNED_NUMBER (1, tp->tm_mon < -3, tp->tm_mon / 3 + 1U);
>> +          break;
> 
> I don't think we have DO_SIGNED_NUMBER in glibc.
> 

Indeed and you need to indicate how/where exactly you have tested
it.
  
Joseph Myers Nov. 3, 2016, 9:59 p.m. UTC | #3
On Thu, 3 Nov 2016, Florian Weimer wrote:

> * Pádraig Brady:
> 
> > This is already supported by gnulib.
> 
> This needs a test case (at least a test case update).

And a NEWS entry.
  
Rafal Luzynski Nov. 4, 2016, 11:33 a.m. UTC | #4
Hi,

Shouldn't strptime() family also support the same?

Regards,

Rafal
  
Szabolcs Nagy Nov. 4, 2016, 11:41 a.m. UTC | #5
On 03/11/16 19:46, Pádraig Brady wrote:
> This is already supported by gnulib.

why?
  
Pádraig Brady Nov. 4, 2016, noon UTC | #6
On 04/11/16 11:41, Szabolcs Nagy wrote:
> On 03/11/16 19:46, Pádraig Brady wrote:
>> This is already supported by gnulib.

> why?

It's a marginal benefit, but as
noted in the cover of my updated patch:

"Note even though the code is trivial here,
%q is useful from the shell as there you need to:
$(( ($(date +%-m)-1)/3+1 ))".

I'll add that to the actual commit.
  
Szabolcs Nagy Nov. 4, 2016, 12:07 p.m. UTC | #7
On 04/11/16 12:00, Pádraig Brady wrote:
> On 04/11/16 11:41, Szabolcs Nagy wrote:
>> On 03/11/16 19:46, Pádraig Brady wrote:
>>> This is already supported by gnulib.
> 
>> why?
> 
> It's a marginal benefit, but as
> noted in the cover of my updated patch:
> 
> "Note even though the code is trivial here,
> %q is useful from the shell as there you need to:
> $(( ($(date +%-m)-1)/3+1 ))".
> 
> I'll add that to the actual commit.

this can conflict with future standard, so
there need to be a strong reason for adding
such extensions to portability libraries
such as gnulib or to c runtimes.

how does gnulib plan to deal with the conflict
once posix adds %q with different meaning?
  
Pádraig Brady Nov. 4, 2016, 12:23 p.m. UTC | #8
On 04/11/16 12:07, Szabolcs Nagy wrote:
> On 04/11/16 12:00, Pádraig Brady wrote:
>> On 04/11/16 11:41, Szabolcs Nagy wrote:
>>> On 03/11/16 19:46, Pádraig Brady wrote:
>>>> This is already supported by gnulib.
>>
>>> why?
>>
>> It's a marginal benefit, but as
>> noted in the cover of my updated patch:
>>
>> "Note even though the code is trivial here,
>> %q is useful from the shell as there you need to:
>> $(( ($(date +%-m)-1)/3+1 ))".
>>
>> I'll add that to the actual commit.
> 
> this can conflict with future standard, so
> there need to be a strong reason for adding
> such extensions to portability libraries
> such as gnulib or to c runtimes.
> 
> how does gnulib plan to deal with the conflict
> once posix adds %q with different meaning?

Perl's date lib also uses %q for quarter.
So between that and gnulib (and glibc?)
POSIX would be unlikely to choose %q for something else.
In any case I intend to propose it to the POSIX folks.

thanks,
Pádraig
  
Szabolcs Nagy Nov. 4, 2016, 12:41 p.m. UTC | #9
On 04/11/16 12:23, Pádraig Brady wrote:
> On 04/11/16 12:07, Szabolcs Nagy wrote:
>> On 04/11/16 12:00, Pádraig Brady wrote:
>>> On 04/11/16 11:41, Szabolcs Nagy wrote:
>>>> On 03/11/16 19:46, Pádraig Brady wrote:
>>>>> This is already supported by gnulib.
>>>
>>>> why?
>>>
>>> It's a marginal benefit, but as
>>> noted in the cover of my updated patch:
>>>
>>> "Note even though the code is trivial here,
>>> %q is useful from the shell as there you need to:
>>> $(( ($(date +%-m)-1)/3+1 ))".
>>>
>>> I'll add that to the actual commit.
>>
>> this can conflict with future standard, so
>> there need to be a strong reason for adding
>> such extensions to portability libraries
>> such as gnulib or to c runtimes.
>>
>> how does gnulib plan to deal with the conflict
>> once posix adds %q with different meaning?
> 
> Perl's date lib also uses %q for quarter.

i don't know what "Perl's date lib" is,
the perl DateTime module does not seem to support %q.
https://metacpan.org/pod/DateTime#strftime-Patterns

> So between that and gnulib (and glibc?)
> POSIX would be unlikely to choose %q for something else.
> In any case I intend to propose it to the POSIX folks.
> 
> thanks,
> Pádraig
>
  
Pádraig Brady Nov. 4, 2016, 12:58 p.m. UTC | #10
On 04/11/16 12:41, Szabolcs Nagy wrote:
> On 04/11/16 12:23, Pádraig Brady wrote:
>> On 04/11/16 12:07, Szabolcs Nagy wrote:
>>> On 04/11/16 12:00, Pádraig Brady wrote:
>>>> On 04/11/16 11:41, Szabolcs Nagy wrote:
>>>>> On 03/11/16 19:46, Pádraig Brady wrote:
>>>>>> This is already supported by gnulib.
>>>>
>>>>> why?
>>>>
>>>> It's a marginal benefit, but as
>>>> noted in the cover of my updated patch:
>>>>
>>>> "Note even though the code is trivial here,
>>>> %q is useful from the shell as there you need to:
>>>> $(( ($(date +%-m)-1)/3+1 ))".
>>>>
>>>> I'll add that to the actual commit.
>>>
>>> this can conflict with future standard, so
>>> there need to be a strong reason for adding
>>> such extensions to portability libraries
>>> such as gnulib or to c runtimes.
>>>
>>> how does gnulib plan to deal with the conflict
>>> once posix adds %q with different meaning?
>>
>> Perl's date lib also uses %q for quarter.
> 
> i don't know what "Perl's date lib" is,
> the perl DateTime module does not seem to support %q.
> https://metacpan.org/pod/DateTime#strftime-Patterns

Sorry Perl's Date::Format supports %q
https://metacpan.org/pod/Date::Format#CONVERSION-SPECIFICATION
  
keld@keldix.com Nov. 4, 2016, 1:12 p.m. UTC | #11
ISO 30112 will poropose %q in the new revision.
I think it is difficult for POSIX then to do something else.

Have you got standardese for the %q spec, which I can use in 30112?

Best regards
keld

On Fri, Nov 04, 2016 at 12:23:28PM +0000, Pádraig Brady wrote:
> On 04/11/16 12:07, Szabolcs Nagy wrote:
> > On 04/11/16 12:00, Pádraig Brady wrote:
> >> On 04/11/16 11:41, Szabolcs Nagy wrote:
> >>> On 03/11/16 19:46, Pádraig Brady wrote:
> >>>> This is already supported by gnulib.
> >>
> >>> why?
> >>
> >> It's a marginal benefit, but as
> >> noted in the cover of my updated patch:
> >>
> >> "Note even though the code is trivial here,
> >> %q is useful from the shell as there you need to:
> >> $(( ($(date +%-m)-1)/3+1 ))".
> >>
> >> I'll add that to the actual commit.
> > 
> > this can conflict with future standard, so
> > there need to be a strong reason for adding
> > such extensions to portability libraries
> > such as gnulib or to c runtimes.
> > 
> > how does gnulib plan to deal with the conflict
> > once posix adds %q with different meaning?
> 
> Perl's date lib also uses %q for quarter.
> So between that and gnulib (and glibc?)
> POSIX would be unlikely to choose %q for something else.
> In any case I intend to propose it to the POSIX folks.
> 
> thanks,
> Pádraig
  
Szabolcs Nagy Nov. 4, 2016, 2:12 p.m. UTC | #12
On 04/11/16 13:12, keld@keldix.com wrote:
> ISO 30112 will poropose %q in the new revision.
> I think it is difficult for POSIX then to do something else.

this should be the other way around: propose the interface
to posix, then add locale specifications later, otherwise
the two standards can diverge.
  
Adhemerval Zanella Netto Nov. 4, 2016, 2:57 p.m. UTC | #13
On 04/11/2016 12:12, Szabolcs Nagy wrote:
> On 04/11/16 13:12, keld@keldix.com wrote:
>> ISO 30112 will poropose %q in the new revision.
>> I think it is difficult for POSIX then to do something else.
> 
> this should be the other way around: propose the interface
> to posix, then add locale specifications later, otherwise
> the two standards can diverge.

I tend to agree with this rationale.
  
keld@keldix.com Nov. 5, 2016, 7:18 a.m. UTC | #14
On Fri, Nov 04, 2016 at 02:12:28PM +0000, Szabolcs Nagy wrote:
> On 04/11/16 13:12, keld@keldix.com wrote:
> > ISO 30112 will poropose %q in the new revision.
> > I think it is difficult for POSIX then to do something else.
> 
> this should be the other way around: propose the interface
> to posix, then add locale specifications later, otherwise
> the two standards can diverge.

Oh, well, 30112 has taken the lead  on many i18n issues, and this is also the agreement with the posix folks.

Best regards
keld
  

Patch

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;