From patchwork Fri Nov 4 01:46:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?P=C3=A1draig_Brady?= X-Patchwork-Id: 80764 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp926792qge; Thu, 3 Nov 2016 18:47:25 -0700 (PDT) X-Received: by 10.98.17.80 with SMTP id z77mr22130267pfi.166.1478224045386; Thu, 03 Nov 2016 18:47:25 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id q28si12862397pfl.44.2016.11.03.18.47.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 03 Nov 2016 18:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-74380-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-74380-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-74380-patch=linaro.org@sourceware.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type; q=dns; s=default; b=b1CU MiW6W/MyC7IDXrFSlTrEOPQfqY6KVqC7k27ptrphiSV0nvRaGHgnAuXRRKL6h7gX rynADsfbMEaBTaIrfVpOBIpAb7j4Lv1PiFzKKEGfG+QK5bk9SLjxbLxyU0p6obSs iTOv7dlf7ExKdCDVV6/PXE01nvtiou0ctiAvBvM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type; s=default; bh=KT38ap4kjL 95aMQEJaSzame/Tgk=; b=tdasOS4ZFDlOqA7nscRrtr4DHQVV+0JUGZFKLhXr2O UjDVNtmFWWMp/quJDa/2y1X9QTlmP6IfFugLKfVrngf5iyXJFz2t8UjTbDlv3ndM 8cF+1Xpb2nzA4HBQH+j115MS5kSRuV8bAS7TIIYGMngbJs+GABjp0D3cxZo2V46d E= Received: (qmail 46377 invoked by alias); 4 Nov 2016 01:47:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 43982 invoked by uid 89); 4 Nov 2016 01:47:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.5 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 spammy=H*r:sk:mail.ma, H*RU:sk:mail.ma, Hx-spam-relays-external:sk:mail.ma, Quarter X-HELO: mail.magicbluesmoke.com Subject: Re: [PATCH] strftime: support %q to output the quarter of year To: libc-alpha@sourceware.org References: <1478202401-5238-1-git-send-email-P@draigBrady.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Fri, 4 Nov 2016 01:46:52 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1478202401-5238-1-git-send-email-P@draigBrady.com> Updated patch attached. Tested using: sudo alternatives --set ld /usr/bin/ld.bfd mkdir build.tmp cd build.tmp ../configure --quiet --disable-sanity-checks make PARALLELMFLAGS=-j$(nproc) make -r PARALLELMFLAGS=-j$(nproc) -C $PWD/../time objdir=$(pwd) check ./testrun.sh time/tst-strftime && echo ok Note even though the code is trivial here, %q is useful as from the shell you need to: $(( ($(date +%-m)-1)/3+1 )) thanks, Pádraig. >From 137cc31d7870e3ecda6c67cda47e29ace2c5acf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 3 Nov 2016 19:36:59 +0000 Subject: [PATCH] strftime: support %q to output the quarter of year This is already supported by gnulib. * manual/time.texi: Document %q outputs quarter 1..4. * time/strftime_l.c: Implement %q. * time/tst-strftime.c: Add a test case. * NEWS: Mention the new feature. --- NEWS | 2 ++ manual/time.texi | 6 ++++++ time/strftime_l.c | 4 ++++ time/tst-strftime.c | 27 +++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/NEWS b/NEWS index 65184b1..9b9fa33 100644 --- a/NEWS +++ b/NEWS @@ -119,6 +119,8 @@ Version 2.25 variable for a particular architecture in the GCC source file 'gcc/config.gcc'. +* strftime now supports the %q directive to output the quarter of the year. + Security related changes: On ARM EABI (32-bit), generating a backtrace for execution contexts which diff --git a/manual/time.texi b/manual/time.texi index 6a899b7..b6466d1 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 1205035..25746a0 100644 --- a/time/strftime_l.c +++ b/time/strftime_l.c @@ -1085,6 +1085,10 @@ __strftime_internal (CHAR_T *s, size_t maxsize, const CHAR_T *format, goto underlying_strftime; #endif + case L_('q'): /* GNU extension. */ + DO_NUMBER (1, tp->tm_mon / 3 + 1); + break; + case L_('R'): subfmt = L_("%H:%M"); goto subformat; diff --git a/time/tst-strftime.c b/time/tst-strftime.c index af3ff72..d087266 100644 --- a/time/tst-strftime.c +++ b/time/tst-strftime.c @@ -154,6 +154,33 @@ do_test (void) } } + /* Check %q. */ + for (size_t mon = 1; mon <= 12; mon++) + { + char out[2]; + char exp[2] = {0,}; + struct tm qtm = { .tm_mon = mon - 1 }; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat" + size_t r = strftime (out, sizeof (out), "%q", &qtm); +#pragma GCC diagnostic pop + if (r == 0) + { + puts ("strftime(\"%q\") failed"); + result = 1; + break; + } + + exp[0] = mon < 4 ? '1' : mon < 7 ? '2' : mon < 10 ? '3' : '4'; + if (strcmp (out, exp) != 0) + { + printf ("strftime %%q: expected \"%s\", got \"%s\"\n", exp, out); + result = 1; + break; + } + } + return result + do_bz18985 (); } -- 2.5.5