Apply the leading duration sign as components are parsed, avoiding a second pass for negative durations.
Track allowed date and time units with ordered positions instead of keyword-list tails and recursive lookups.
Assisted-by: Codex:GPT-5
The preceding clauses handle steps that point away from the last date.
Otherwise, `last_days - first_days` and `step` have the same sign,
so `div/2` is already non-negative.
The `:day`, `:hour` and `:minute` clauses of `Time.diff/3`,
`DateTime.diff/3` and `NaiveDateTime.diff/3` compute the difference in
seconds first and then divide again, so the sub-second remainder is
rounded twice. The intermediate conversion floors while the final
`div/2` truncates, so the result follows neither rule:
# elapsed is 23:59:59.999998, less than a full day
Time.diff(~T[00:00:00.000001], ~T[23:59:59.999999], :hour)
#=> -24, while the opposite direction returns 23
# elapsed is 86399.5s, and the docs promise incomplete days round to zero
NaiveDateTime.diff(~N[2000-01-01 00:00:00.7], ~N[2000-01-02 00:00:00.2], :day)
#=> -1
Compute the difference in microseconds and divide once instead. This
keeps the documented truncation ("fractional results are not supported
and are truncated", "it also rounds incomplete days to zero") in both
directions. Positive results are unchanged, so the existing
`DateTime.diff/3` "almost 7 days" test now gains its negative
counterpart.
Assisted-by: Claude Code:claude-opus-4-8
This test runs `System.cmd/3` against a symlink to the `echo` command.
This works when `echo` is its own binary and when it's in a multicall
binary that's dispatched using `argv[0]`. It doesn't work for the new
Rust/uutils coreutils which doesn't dispatch via `argv[0]`. In this
case, intended call to echo produces no output:
```
1) test Unix cmd/3 with absolute and relative paths (SystemTest)
test/elixir/system_test.exs:210
match (=) failed
code: assert {"hello\n", 0} = System.cmd(Path.join(File.cwd!(), @echo), ["hello"], arg0: "echo")
left: {"hello\n", 0}
right: {"", 0}
stacktrace:
test/elixir/system_test.exs:223: anonymous fn/0 in SystemTest."test Unix cmd/3 with absolute and relative paths"/1
(elixir 1.21.0-dev) lib/file.ex:2100: File.cd!/2
test/elixir/system_test.exs:215: (test)
```
This fix switches the binary used for the test over to `sh` which fixes
the issue on Ubuntu 26.04. This was also verified on Ubuntu 24.04,
Ubuntu 22.04, Alpine Linux 3.24, macOS Tahoe (26.5.1) and MacOS Sequoia
(15.3.2).