Skip to content

Commit 6917b4c

Browse files
authored
os: ns_to_sec rounding (RustPython#5150)
In cpython, they use `_PyTime_ROUND_FLOOR` to read time. But in RustPython, we use `[Duration::from_secs_f64](https://doc.rust-lang.org/std/time/struct.Duration.html#method.try_from_secs_f64)` to read time. Therefore, RustPython isn't affected by the rounding issue in the way that cpython does. We can safely ignore the `0.5*1e-9` bit in `ns_to_sec` function.
1 parent aaae566 commit 6917b4c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Lib/test/test_os.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,10 +815,10 @@ def ns_to_sec(ns):
815815
# Convert a number of nanosecond (int) to a number of seconds (float).
816816
# Round towards infinity by adding 0.5 nanosecond to avoid rounding
817817
# issue, os.utime() rounds towards minus infinity.
818-
return (ns * 1e-9) + 0.5e-9
818+
# XXX: RUSTCPYTHON os.utime() use `[Duration::from_secs_f64](https://doc.rust-lang.org/std/time/struct.Duration.html#method.try_from_secs_f64)`
819+
# return (ns * 1e-9) + 0.5e-9
820+
return (ns * 1e-9)
819821

820-
# TODO: RUSTPYTHON
821-
@unittest.expectedFailure
822822
def test_utime_by_indexed(self):
823823
# pass times as floating point seconds as the second indexed parameter
824824
def set_time(filename, ns):
@@ -830,8 +830,6 @@ def set_time(filename, ns):
830830
os.utime(filename, (atime, mtime))
831831
self._test_utime(set_time)
832832

833-
# TODO: RUSTPYTHON
834-
@unittest.expectedFailure
835833
def test_utime_by_times(self):
836834
def set_time(filename, ns):
837835
atime_ns, mtime_ns = ns

0 commit comments

Comments
 (0)