File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,9 @@ def __time_val_to_str(time):
4141 :return: The string representation.
4242 :rtype: str
4343 """
44- return "%i.%09i" % (time .secs , time .nsecs )
44+ # We can't directly print .secs, .nsecs, as that would fail for negative durations
45+ nsecs = time .to_nsec ()
46+ return "%i.%09i" % (nsecs // 1000000000 , nsecs % 1000000000 )
4547
4648
4749__to_str_functions = {
Original file line number Diff line number Diff line change @@ -51,8 +51,10 @@ def test_to_str(self):
5151 self .assertEqual ("1.000000001" , to_str (Duration (1 , 1 )))
5252 self .assertEqual ("1.100000000" , to_str (Duration (1 , 100000000 )))
5353 self .assertEqual ("-1.000000000" , to_str (- Duration (1 )))
54- self .assertEqual ("-1.000000001" , to_str (Duration (- 1 , 1 )))
55- self .assertEqual ("-1.100000000" , to_str (Duration (- 1 , 100000000 )))
54+ # negative durations mean "10e9 * secs + nsecs", so (-1, 1) is actually
55+ # (-1 * 10e9 + 1) = -999999999
56+ self .assertEqual ("-0.999999999" , to_str (Duration (- 1 , 1 )))
57+ self .assertEqual ("-0.9" , to_str (Duration (- 1 , 100000000 )))
5658 self .assertEqual ("1.000000000" , to_str (Time (1 )))
5759 self .assertEqual ("1.000000001" , to_str (Time (1 , 1 )))
5860 self .assertEqual ("1.100000000" , to_str (Time (1 , 100000000 )))
You can’t perform that action at this time.
0 commit comments