Align os.utime float-to-duration rounding with CPython semantics by Copilot · Pull Request #6501 · RustPython/RustPython
os.utime float inputs regressed due to Rust Duration::from_secs_f64 rounding changes; CPython floors times toward -∞. This patch restores CPython-equivalent flooring to keep test_utime_by_indexed/times passing.
- Float-to-duration conversion: Replace
Duration::from_secs_f64with explicit nanosecond flooring, sign/finite checks, and bounds enforcement against the max(u64 seconds, <1e9 ns)duration. - Rounding parity: Ensure flooring behavior mirrors
_PyTime_DoubleToDenominatorforos.utimepaths while preserving integer handling.
Example:
// Before: Duration::from_secs_f64(f) // After: let total_nanos = (f * 1_000_000_000f64).floor(); let secs = (total_nanos as u128 / 1_000_000_000) as u64; let nanos = (total_nanos as u128 % 1_000_000_000) as u32; let dur = std::time::Duration::new(secs, nanos);
Original prompt
This section details on the original issue you should resolve
<issue_title>Tracking issue of os.utime regression</issue_title>
<issue_description>std::time::Duration::from_secs_f64behavior is changed in Rust 1.63.related python test:
test_os::test_utime_by_indexedtest_os::test_utime_by_timestest command:
cargo +stable run Lib/test/test_os.py -k utime -vcargo +1.62.1 run Lib/test/test_os.py -k utime -vRust issue including minimal reproducible code
To-do
We will stay on 1.62.1 until checking if it is a rust bug or intended change.
Once it is resolved:
- Revert CI changes set CI toolchain to 1.62.1 #4046</issue_description>
<agent_instructions>Implement something similar like _PyTime_DoubleToDenominator and resolve the related python test to pass (not as expectedFailure)</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@youknowone In CPython, `_PyTime_DoubleToDenominator` provides rounding option. floor option is passed for this path. @youknowone It was an intended behavior change from Rust. we need to implement rounding option like cpython.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.