Commit 20bc8c1e authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Petr Mladek

lib/vsprintf: Allow to override ISO 8601 date and time separator

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Reviewed-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: default avatarPetr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20210511153958.34527-1-andriy.shevchenko@linux.intel.com
parent 7f3d08b2
...@@ -514,9 +514,10 @@ Time and date ...@@ -514,9 +514,10 @@ Time and date
:: ::
%pt[RT] YYYY-mm-ddTHH:MM:SS %pt[RT] YYYY-mm-ddTHH:MM:SS
%pt[RT]s YYYY-mm-dd HH:MM:SS
%pt[RT]d YYYY-mm-dd %pt[RT]d YYYY-mm-dd
%pt[RT]t HH:MM:SS %pt[RT]t HH:MM:SS
%pt[RT][dt][r] %pt[RT][dt][r][s]
For printing date and time as represented by:: For printing date and time as represented by::
...@@ -528,6 +529,10 @@ in human readable format. ...@@ -528,6 +529,10 @@ in human readable format.
By default year will be incremented by 1900 and month by 1. By default year will be incremented by 1900 and month by 1.
Use %pt[RT]r (raw) to suppress this behaviour. 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. Passed by reference.
struct clk struct clk
......
...@@ -528,6 +528,11 @@ time_and_date(void) ...@@ -528,6 +528,11 @@ time_and_date(void)
test("0119-00-04T15:32:23", "%ptTr", &t); test("0119-00-04T15:32:23", "%ptTr", &t);
test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t); test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t);
test("15:32:23|0119-00-04", "%ptTtr|%ptTdr", &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 static void __init
......
...@@ -1798,7 +1798,8 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm, ...@@ -1798,7 +1798,8 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
struct printf_spec spec, const char *fmt) struct printf_spec spec, const char *fmt)
{ {
bool have_t = true, have_d = true; bool have_t = true, have_d = true;
bool raw = false; bool raw = false, iso8601_separator = true;
bool found = true;
int count = 2; int count = 2;
if (check_pointer(&buf, end, tm, spec)) if (check_pointer(&buf, end, tm, spec))
...@@ -1815,14 +1816,25 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm, ...@@ -1815,14 +1816,25 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
break; 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) if (have_d)
buf = date_str(buf, end, tm, raw); buf = date_str(buf, end, tm, raw);
if (have_d && have_t) { if (have_d && have_t) {
/* Respect ISO 8601 */
if (buf < end) if (buf < end)
*buf = 'T'; *buf = iso8601_separator ? 'T' : ' ';
buf++; buf++;
} }
if (have_t) if (have_t)
...@@ -2261,7 +2273,7 @@ early_param("no_hash_pointers", no_hash_pointers_enable); ...@@ -2261,7 +2273,7 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
* - 'd[234]' For a dentry name (optionally 2-4 last components) * - 'd[234]' For a dentry name (optionally 2-4 last components)
* - 'D[234]' Same as 'd' but for a struct file * - 'D[234]' Same as 'd' but for a struct file
* - 'g' For block_device name (gendisk + partition number) * - '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 * R struct rtc_time
* T time64_t * T time64_t
* - 'C' For a clock, it prints the name (Common Clock Framework) or address * - 'C' For a clock, it prints the name (Common Clock Framework) or address
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment