Skip to content

date: strftime ignores flags and widths on %N (nanoseconds) #11658

Closed

Description

@sylvestre

Summary

GNU date honours strftime flags and widths on %N (nanoseconds). uutils ignores or mishandles them: %_3N should space-pad to width 3, and %-N should still emit the full 9-digit default, but uutils emits a single 0.

Found by a fuzz_date run.

Reproduction

$ LC_ALL=C TZ=UTC /usr/bin/date -d '@0' '+%_3N' | od -c | head -1
0000000   0                \n

$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '@0' '+%_3N' | od -c | head -1
0000000   0  \n

$ LC_ALL=C TZ=UTC /usr/bin/date -d '@0' '+%-N'
000000000

$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '@0' '+%-N'
0

Test

#[test]
fn test_date_strftime_n_width_and_flags() {
    new_ucmd!()
        .env("LC_ALL", "C")
        .env("TZ", "UTC")
        .arg("-d")
        .arg("@0")
        .arg("+%_3N")
        .succeeds()
        .stdout_is("0  \n");

    new_ucmd!()
        .env("LC_ALL", "C")
        .env("TZ", "UTC")
        .arg("-d")
        .arg("@0")
        .arg("+%-N")
        .succeeds()
        .stdout_is("000000000\n");
}

Activity

  1. 139 remaining items

  2. xtqqczze commented on Oct 10, 2026

    @xtqqczze
    Collaborator

    @anastygnome Is this issue not fully resolved?

  3. anastygnome commented on Oct 10, 2026

    @anastygnome
    Contributor

    No, there were missing edge cases, see unignored tests

  4. xtqqczze commented on Nov 20, 2026

    @xtqqczze
    Collaborator

    @anastygnome have the edge cases now been fixed?

  5. anastygnome commented on Nov 20, 2026

    @anastygnome
    Contributor

    @xtqqczze we'll need a new parse_datetime release

  6. xtqqczze commented on Nov 20, 2026

    @xtqqczze
    Collaborator

    OK would you open an issue to track the edge cases?

  7. anastygnome commented on Nov 20, 2026

    @anastygnome
    Contributor

    @sylvestre can we reopen

  8. xtqqczze commented on Nov 20, 2026

    @xtqqczze
    Collaborator

    @anastygnome It seems the issue described in the original report is no longer reproducible. If you’re aware of any other related issues, could you please open a separate issue to track them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions