Discussion:
[PATCH] support for quarter from strftime (%q)
(too old to reply)
Pádraig Brady
2016-11-02 15:25:20 UTC
Permalink
Raw Message
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
Pádraig Brady
2016-11-05 16:59:04 UTC
Permalink
Raw Message
Post by Pádraig Brady
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.
I proposed this for glibc with little push back,
and the only significant suggestion to add to strptime()
also for consistency. Therefore I did that in the attached,
added a test, and pushed.


thanks,
Pádraig.
Paul Eggert
2016-11-13 01:43:56 UTC
Permalink
Raw Message
Thanks, and we can tune the gnulib strftime %q the same way as glibc so I
installed the attached.
Bruno Haible
2016-11-14 21:10:59 UTC
Permalink
Raw Message
Hi Pádraig,
Post by Pádraig Brady
add to strptime()
also for consistency. Therefore I did that in the attached,
added a test, and pushed.
If users of the 'strptime' module should be able to rely on the %q feature,
it requires also a change in doc/posix-functions/strptime.texi and
m4/strptime.m4, modules/strptime, etc. Because so far, on platforms where
strptime exists and does not support %q, this code will *not* override it:
if test $HAVE_STRPTIME = 0; then
AC_LIBOBJ([strptime])
gl_PREREQ_STRPTIME
fi

Or was it meant to be an undocumented feature? Then the unit test should
be conditionalized.

Bruno
Pádraig Brady
2016-11-14 22:35:30 UTC
Permalink
Raw Message
Post by Bruno Haible
Hi Pádraig,
Post by Pádraig Brady
add to strptime()
also for consistency. Therefore I did that in the attached,
added a test, and pushed.
If users of the 'strptime' module should be able to rely on the %q feature,
it requires also a change in doc/posix-functions/strptime.texi and
m4/strptime.m4, modules/strptime, etc. Because so far, on platforms where
if test $HAVE_STRPTIME = 0; then
AC_LIBOBJ([strptime])
gl_PREREQ_STRPTIME
fi
Or was it meant to be an undocumented feature? Then the unit test should
be conditionalized.
Currently there is no strptime unit test.
It's not worth replacing strptime to support %q, at least until it's available in glibc.
In retrospect I probably should have not added it to gnulib until it hits glibc.
I was just adding it to keep more in sync
(assuming the %q patch would eventually land in glibc).

nstrftime() is another story as that's generally replaced already,
and %q is much more useful there.

thanks,
Pádraig.
Bruno Haible
2016-11-15 06:49:03 UTC
Permalink
Raw Message
Post by Pádraig Brady
It's not worth replacing strptime to support %q, at least until it's available in glibc.
OK.
Post by Pádraig Brady
Currently there is no strptime unit test.
Ah, right. Sorry for the noise then.

Bruno

Loading...