Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3639167pxj; Tue, 11 May 2021 08:42:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmsSetrt7AnpWkgFNFJQw+iHnZB3220xYBmBQbMkGYw78rT6i22K11+L6JXIw0pr+jLsxN X-Received: by 2002:a17:907:3d8f:: with SMTP id he15mr32009524ejc.22.1620747720341; Tue, 11 May 2021 08:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620747720; cv=none; d=google.com; s=arc-20160816; b=psmrg1Ygf1WoC9+OG5WN6PVteJ8Ck5upyExKMkNCV0nSRwgqXtYL2ziVTPSMfeRNZv wGNgu4GR29PqsZHoJIXxqvwZnSatm8xv3CbWEym6+KRlZ+8P9ZIeSFSmNEtMARgj/NSO Os45zTj6kyCSPBSiMggpG5MkltLx+t2oCEmYn6OyW+2OxwXmgNNzSkFzz9uCWamgqA5z CePDeyHYnC9dhWPyfgi4TxT5YTv9EmaAC4QZqMMj6qwrkTBgIvX0CLZUQ7v4OFkxTwYv VnHxvmcBwzgNd1+S+Vunq0C6YA3XKXqnAGT3qGyOL4AhE6Zv1s33OgYmSZGQ7RBfSxX+ 0RRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=wbgQjGe3g3yszoqHAZDrtdS2KszpmGd0Nv94KR3A70w=; b=z0+i/mxBvaJ1mHAkdsh2CNdY3k9kP8etgvQN+I/DwU2GhG47t3+WHXyDB+bNz/jX0l 8XZenbtpTiK7IvhX5zD6uc4aPz+0OGZzKUH/NOLwcY9wJlA2/IkuML0x2pEdgItJ2XKp FmWBH2xtDnOz6Zvz/N9Tt2rZ1wCUT7Ih6aSuC6S4ZkOOquMb5Ifj49Xsz1qg2CG82X6u n9LBws27R+ROKcbT00EIumc3s6Ig/lAkFziKAsS4Dposb85kcjrb7Vlt7leKeutW1SlI vpM7KasxM5ttpPqhFQooyueIDjBCxFt1f3dIY+a8MHF5pYMWTc35ZwDzJPWKMmu2ZhT8 V+nQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds10si21698469ejc.719.2021.05.11.08.41.36; Tue, 11 May 2021 08:42:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231891AbhEKPlJ (ORCPT + 99 others); Tue, 11 May 2021 11:41:09 -0400 Received: from mga06.intel.com ([134.134.136.31]:28260 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231950AbhEKPlF (ORCPT ); Tue, 11 May 2021 11:41:05 -0400 IronPort-SDR: 4CvMoR5p5RTzYkYGS4ujcI/gf9dP23Z9j1enE8tuM9NkLaYC7FwokJWPVKm9w6qYCL8PAsasSs 9uKgykm11liQ== X-IronPort-AV: E=McAfee;i="6200,9189,9981"; a="260734862" X-IronPort-AV: E=Sophos;i="5.82,291,1613462400"; d="scan'208";a="260734862" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2021 08:39:45 -0700 IronPort-SDR: BmOdmLk95HugbOBhf/VKi8M9ccrx7snWj519gBrlC2bQnNhtXA3yQfhaFPsqxh2n6tgM7lv4WM FP1+rlI4gmjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,291,1613462400"; d="scan'208";a="434604794" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 11 May 2021 08:39:40 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2186BD7; Tue, 11 May 2021 18:40:00 +0300 (EEST) From: Andy Shevchenko To: Petr Mladek , JC Kuo , Joe Perches , Sumit Garg , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-tegra@vger.kernel.org, linux-nilfs@vger.kernel.org, kgdb-bugreport@lists.sourceforge.net Cc: Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Mathias Nyman , Greg Kroah-Hartman , Thierry Reding , Jonathan Hunter , Ryusuke Konishi , Jason Wessel , Daniel Thompson , Douglas Anderson Subject: [PATCH v2 1/4] lib/vsprintf: Allow to override ISO 8601 date and time separator Date: Tue, 11 May 2021 18:39:55 +0300 Message-Id: <20210511153958.34527-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ISO 8601 defines 'T' as a separator between date and time. Though, some ABIs use time and date with ' ' (space) separator instead. Add a flavour to the %pt specifier to override default separator. Signed-off-by: Andy Shevchenko --- v2: fixed the parameters set, renamed variable and dropped comment (Petr) Documentation/core-api/printk-formats.rst | 7 ++++++- lib/test_printf.c | 5 +++++ lib/vsprintf.c | 22 +++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index f063a384c7c8..1dd4ebf0be79 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -514,9 +514,10 @@ Time and date :: %pt[RT] YYYY-mm-ddTHH:MM:SS + %pt[RT]s YYYY-mm-dd HH:MM:SS %pt[RT]d YYYY-mm-dd %pt[RT]t HH:MM:SS - %pt[RT][dt][r] + %pt[RT][dt][r][s] For printing date and time as represented by:: @@ -528,6 +529,10 @@ in human readable format. By default year will be incremented by 1900 and month by 1. Use %pt[RT]r (raw) to suppress this behaviour. +The %pt[RT]s (space) will override ISO 8601 separator by using ' ' (space) +instead of 'T' (Capital T) between date and time. It won't have any effect +when date or time is omitted. + Passed by reference. struct clk diff --git a/lib/test_printf.c b/lib/test_printf.c index ec0d5976bb69..8ac71aee46af 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -528,6 +528,11 @@ time_and_date(void) test("0119-00-04T15:32:23", "%ptTr", &t); test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t); test("15:32:23|0119-00-04", "%ptTtr|%ptTdr", &t, &t); + + test("2019-01-04 15:32:23", "%ptTs", &t); + test("0119-00-04 15:32:23", "%ptTsr", &t); + test("15:32:23|2019-01-04", "%ptTts|%ptTds", &t, &t); + test("15:32:23|0119-00-04", "%ptTtrs|%ptTdrs", &t, &t); } static void __init diff --git a/lib/vsprintf.c b/lib/vsprintf.c index f0c35d9b65bf..14a4e4e8a657 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1834,7 +1834,8 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm, struct printf_spec spec, const char *fmt) { bool have_t = true, have_d = true; - bool raw = false; + bool raw = false, iso8601_separator = true; + bool found = true; int count = 2; if (check_pointer(&buf, end, tm, spec)) @@ -1851,14 +1852,25 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm, break; } - raw = fmt[count] == 'r'; + do { + switch (fmt[count++]) { + case 'r': + raw = true; + break; + case 's': + iso8601_separator = false; + break; + default: + found = false; + break; + } + } while (found); if (have_d) buf = date_str(buf, end, tm, raw); if (have_d && have_t) { - /* Respect ISO 8601 */ if (buf < end) - *buf = 'T'; + *buf = iso8601_separator ? 'T' : ' '; buf++; } if (have_t) @@ -2298,7 +2310,7 @@ early_param("no_hash_pointers", no_hash_pointers_enable); * - 'd[234]' For a dentry name (optionally 2-4 last components) * - 'D[234]' Same as 'd' but for a struct file * - 'g' For block_device name (gendisk + partition number) - * - 't[RT][dt][r]' For time and date as represented by: + * - 't[RT][dt][r][s]' For time and date as represented by: * R struct rtc_time * T time64_t * - 'C' For a clock, it prints the name (Common Clock Framework) or address -- 2.30.2