Page MenuHomeFreeBSD

date: Improve nanosecond support
ClosedPublic

Authored by des on Mon, Nov 10, 4:00 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 18, 2:24 AM
Unknown Object (File)
Thu, Nov 13, 10:48 AM
Unknown Object (File)
Thu, Nov 13, 10:48 AM
Unknown Object (File)
Thu, Nov 13, 10:48 AM
Unknown Object (File)
Thu, Nov 13, 7:03 AM
Unknown Object (File)
Thu, Nov 13, 7:03 AM
Unknown Object (File)
Thu, Nov 13, 7:03 AM
Unknown Object (File)
Thu, Nov 13, 2:40 AM
Subscribers

Details

Summary

Add support for a field width, which defaults to 9 if unspecified or
zero. If the width is not exactly 9, we have to either cut off digits
or append zeroes to make up the difference. This brings us in line
with GNU coreutils, minus the %-N case which we do not handle.

PR: 287080
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Mon, Nov 10, 4:00 PM

Thanks!

Could you also add a note to date.1 saying that %XN is now supported? A note in CAVEATS or BUGS that %-N is not supported would also be good.

des edited the summary of this revision. (Show Details)

add %-N, update documentation

pass resolution through printisodate just in case

The manual page changes and the code changes look OK. Thanks!

I've added a couple of comments you about things you may want to consider before pushing the change.

bin/date/date.1
349
  1. Li is deprecated, so no need to use it here.
  2. Since "-" is effectively a constant here, I'd just go with Cm \&%-N
350

Nit pick: you start here with upper-case "As above" even though in the previous point it's lower-case "where n is". If you care, you may choose to address it.

651–657

You may consider:

Support for
.Ql \&%-N
and custom precision of
.Ql \&%N
was added in
.Fx 16.0 .
bin/date/tests/format_string_test.sh
136

I suspect that adding a test case for -N is a bit annoying as it depends on the host's clock resolution.

This revision is now accepted and ready to land.Mon, Nov 10, 10:03 PM
des marked 4 inline comments as done.Mon, Nov 10, 11:47 PM
des added inline comments.
bin/date/tests/format_string_test.sh
136

Yes, and that can even change at runtime. You _can_ in theory detect it:

tc=$(sysctl -n kern.timecounter.hardware)
freq=$(sysctl -n kern.timecounter.tc.$tc.frequency)
width=$(bc -le "min(l10($freq), 9)$")

but the test script uses the -r option, which forces nsec to 0 and res to 9, so %-N is indistinguishable from %N in testing; they both produce exactly 000000000.

des marked an inline comment as done.Mon, Nov 10, 11:47 PM
This revision now requires review to proceed.Mon, Nov 10, 11:49 PM

Thank you for addressing the nit picks :)

This revision is now accepted and ready to land.Tue, Nov 11, 10:45 AM
This revision was automatically updated to reflect the committed changes.