Skip to content

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

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]fntest_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

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

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions