Skip to content

date input: negative fractional epoch (@-1.5) truncates instead of floors #283

Closed

Description

@sylvestre

Summary

GNU date floors negative fractional epoch inputs (rounds toward negative infinity): @-1.5 → -2. parse_datetime truncates toward zero: @-1.5 → -1. The same off-by-one shows up on any negative fractional @N input.

Found by a fuzz_date run on uutils/coreutils.

Reproduction

$ LC_ALL=C TZ=UTC /usr/bin/date -d '@-1.5' '+%s'
-2

$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '@-1.5' '+%s'
-1

$ LC_ALL=C TZ=UTC /usr/bin/date -d '@-893375784.554767216' '+%s'
-893375785

$ LC_ALL=C TZ=UTC target/debug/coreutils date -d '@-893375784.554767216' '+%s'
-893375784

Positive fractional epochs agree between the two.

Test (in uutils/coreutils integration suite)

#[test]
fn test_date_negative_fractional_epoch_flooring() {
    new_ucmd!()
        .env("LC_ALL", "C")
        .env("TZ", "UTC")
        .arg("-d")
        .arg("@-1.5")
        .arg("+%s")
        .succeeds()
        .stdout_is("-2\n");
}

Activity

  1. added
    bug
    good first issue
    on Apr 5, 2026
  2. added a commit that references this issue on Apr 5, 2026
    c06abc5
  3. added a commit that references this issue on Jun 7, 2026
    900993b
  4. added a commit that references this issue on Jul 5, 2026
    cb1cb02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions