diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-10-19 14:57:57 -0700 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-11-07 17:09:15 +0000 |
commit | 30012b290facf66551cdf395ace397903d00483d (patch) | |
tree | 6fcc03436b7a10a2002ce03d9573689218d5e55c | |
parent | 7ba9355d0aec01a005164b02f7bdc8e67c430315 (diff) | |
download | coreutils-30012b290facf66551cdf395ace397903d00483d.tar.xz |
date: add %q to output the quarter of the year
* doc/coreutils.texi (date invocation): Document %q.
* src/date.c (usage): Likewise.
* tests/misc/date.pl: Add a test case.
* cfg.mk (sc_strftime_check): Adjust to allow %q.
* NEWS: Mention the new feature.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | cfg.mk | 4 | ||||
-rw-r--r-- | doc/coreutils.texi | 2 | ||||
-rw-r--r-- | src/date.c | 1 | ||||
-rwxr-xr-x | tests/misc/date.pl | 5 |
5 files changed, 12 insertions, 2 deletions
@@ -93,6 +93,8 @@ GNU coreutils NEWS -*- outline -*- date now accepts the --debug option, to annotate the parsed date string, display timezone information, and warn about potential misuse. + date now accepts the %q format to output the quarter of the year. + * Noteworthy changes in release 8.25 (2016-01-20) [stable] @@ -434,14 +434,14 @@ sc_prohibit_stat_macro_address: $(_sc_search_regexp) # Ensure that date's --help output stays in sync with the info -# documentation for GNU strftime. The only exception is %N, +# documentation for GNU strftime. The only exception is %N and %q, # which date accepts but GNU strftime does not. extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/' sc_strftime_check: @if test -f $(srcdir)/src/date.c; then \ grep '^ %. ' $(srcdir)/src/date.c | sort \ | $(extract_char) > $@-src; \ - { echo N; \ + { echo N; echo q; \ info libc date calendar format 2>/dev/null \ | grep "^ *['\`]%.'$$"| $(extract_char); }| sort >$@-info;\ if test $$(stat --format %s $@-info) != 2; then \ diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 839af8871..597cf76f0 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -15207,6 +15207,8 @@ same as @samp{%b} day of year (@samp{001}@dots{}@samp{366}) @item %m month (@samp{01}@dots{}@samp{12}) +@item %q +quarter of year (@samp{1}@dots{}@samp{4}) @item %u day of week (@samp{1}@dots{}@samp{7}) with @samp{1} corresponding to Monday @item %U diff --git a/src/date.c b/src/date.c index 9598fc6ea..ddb011e65 100644 --- a/src/date.c +++ b/src/date.c @@ -214,6 +214,7 @@ FORMAT controls the output. Interpreted sequences are:\n\ %N nanoseconds (000000000..999999999)\n\ %p locale's equivalent of either AM or PM; blank if not known\n\ %P like %p, but lower case\n\ + %q quarter of year (1..4)\n\ %r locale's 12-hour clock time (e.g., 11:11:04 PM)\n\ %R 24-hour hour and minute; same as %H:%M\n\ %s seconds since 1970-01-01 00:00:00 UTC\n\ diff --git a/tests/misc/date.pl b/tests/misc/date.pl index 4449a48e4..b53ca81f9 100755 --- a/tests/misc/date.pl +++ b/tests/misc/date.pl @@ -86,6 +86,11 @@ my @Tests = ['W92-2', "--date '1992-1-5' +%W", {OUT=>"00"}], ['W92-3', "--date '1992-1-6' +%W", {OUT=>"01"}], + ['q-1', "--date '1000-1-1' +%q", {OUT=>"1"}], + ['q-2', "--date '1000-4-1' +%q", {OUT=>"2"}], + ['q-3', "--date '1000-7-1' +%q", {OUT=>"3"}], + ['q-4', "--date '1000-10-1' +%q", {OUT=>"4"}], + ['millen-1', "--date '1998-1-1 3 years' +%Y", {OUT=>"2001"}], ['rel-0', "-d '$d1 now' '+%Y-%m-%d %T'", {OUT=>"$d0 $t0"}], |