On 04/11/2025 04:01, Collin Funk wrote:
Many people are used to seeing ISO 8601 dates using a period separating
seconds and nanoseconds. This behavior seems to be worth documenting
given the bug reports:
https://bugs.gnu.org/63119
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1118970

* doc/coreutils.texi (Options for date): Mention that
'date --iso-8601=ns' uses a comma as a separator, following the
preference of ISO 8601. Give an example of how to get an ISO 8601 date
with a period separator.
---
  doc/coreutils.texi | 9 +++++++++
  1 file changed, 9 insertions(+)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 13f9f9a46..a4c9feffc 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -17181,6 +17181,15 @@ @node Options for date
  @item ns
  Also print nanoseconds.
  This is like the format @code{%Y-%m-%dT%H:%M:%S,%N%:z}.
+
+ISO 8601 allows a comma or period to be used to separate seconds from
+subseconds, preferring the use of a comma.  GNU @command{date} follows
+this preference.  If you would prefer to use a period separator, you can
+transform the output of @samp{date --rfc-3339=ns}:
+
+@example
+date --rfc-3339=ns | sed s'/ /T/'
+@end example
  @end table
@macro dateParseNote


I agree this is a bit surprising.
I suppose we could use the current locale's decimal_point,
falling back to , if the locale's wasn't one of [.,].
Though that would introduce varying output when you're asking
for a standard format.

As for the documentation, it seems a little confusing to mix standards.
Note the line above states:

"This is like the format @code{%Y-%m-%dT%H:%M:%S,%N%:z}."

It would be nice to be able to just augment with:

"Note the preference for a @samp(,} decimal point which you can override
by expressing the full format with @samp{.} decimal point explicitly."

However there are complications where just setting the format
would not enable use of the C locale, and looking at the code in date.c
shows complications with doing that with env vars.

So I suppose post processing is what we're left with:
Would the following example be preferable, as it doesn't mix standards,
and uses only coreutils commands.

  date --iso-8691=ns | tr ' ' T

cheers,
Padraig

Reply via email to