]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
date: Add support for nanoseconds
authorMateusz Piotrowski <0mp@FreeBSD.org>
Sun, 21 Apr 2024 21:25:32 +0000 (23:25 +0200)
committerMateusz Piotrowski <0mp@FreeBSD.org>
Fri, 26 Apr 2024 09:26:50 +0000 (11:26 +0200)
commiteeb04a736cb9c07d191af886e25d5f198824658e
tree497ee622a61e04cdc1a8594f2f854156cf677846
parent9b10aa4a05915a6519d942fea48113757dcf1699
date: Add support for nanoseconds

This patch introduces support for a conversion specification for
nanoseconds.

The format of %N is meant to be compatible with that of GNU date.

The nanoseconds conversion specification is implemented directly in
date(1) instead of libc (in strftime(3)) to avoid introducing
non-standard functions to libc at this time and modifying struct tm.

Apart from introducing the nanoseconds conversion specification, this
patch brings the following changes:

- The "ns" format for ISO 8061 dates is now unlocked. E.g., date -Ins
  prints:
      2024-04-22T12:20:28,763742224+02:00
- The -r flag when fed a file is now aware of the nanosecond part of the last
  modification time.
- date(1) is now able to set the time with nanosecond precision. It is
  not possible as of now to do that by specifying nanoseconds directly
  via the command-line arguments. Instead, the -r flag can be used.
- date(1) is now using the clock_gettime(3) family of functions instead
  of ctime(3) family of functions where possible.

Reviewed by: des, markj
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D44905
bin/date/date.1
bin/date/date.c
bin/date/tests/format_string_test.sh