]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
date: add %q to output the quarter of the year
authorPádraig Brady <P@draigBrady.com>
Wed, 19 Oct 2016 21:57:57 +0000 (14:57 -0700)
committerPádraig Brady <P@draigBrady.com>
Mon, 7 Nov 2016 17:09:15 +0000 (17:09 +0000)
* 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.

NEWS
cfg.mk
doc/coreutils.texi
src/date.c
tests/misc/date.pl

diff --git a/NEWS b/NEWS
index 844e23332e6dd65eb3ff901a170a2d799af4b18a..200c12b906da856b8642c07d3186af3bd2653a3b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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]
 
diff --git a/cfg.mk b/cfg.mk
index ece6efa88584aaa69348e21c8574be61b559d5bf..11e42b92fb24cd1d5b4410c0882f56c79ada8518 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -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               \
index 839af8871442ed52197164e6037b2849e628d264..597cf76f0cf3c9b7ca1337de17746f6ebece98fb 100644 (file)
@@ -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
index 9598fc6eafca3cd3afa08190b05461e92e3d40da..ddb011e65892436b2e41092754bcbf40a2164382 100644 (file)
@@ -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\
index 4449a48e44cc8c64ac169270c95c3b598c9a256f..b53ca81f925cd3eebd9a352e1365cc9e8ca917b0 100755 (executable)
@@ -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"}],