From 0bb1c8aab4c7ca7ed66ab756d10131691a4f235e Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 29 Dec 2011 13:32:35 +0000 Subject: produce nanosec timestamps without floating point Go away, stupid rounding error, away! --- summainlib.py | 2 +- summainlib_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/summainlib.py b/summainlib.py index 8eac369..79e64e7 100644 --- a/summainlib.py +++ b/summainlib.py @@ -211,7 +211,7 @@ class FilesystemObject(object): def format_time(self, secs, nsecs): s = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(secs)) - s += ('%.6f' % (nsecs * 1e-9))[1:] # skip leading 0 + s += '.%09d' % nsecs s += ' +0000' return s diff --git a/summainlib_tests.py b/summainlib_tests.py index 8480057..f8bcc27 100644 --- a/summainlib_tests.py +++ b/summainlib_tests.py @@ -109,7 +109,7 @@ class FilesystemObjectTests(unittest.TestCase): def test_formats_mtime_correctly(self): self.assertEqual(self.new('foo')['Mtime'], - '2010-01-01 01:02:03.123457 +0000') + '2010-01-01 01:02:03.123456789 +0000') def test_formats_mode_for_regular_file_correctly(self): self.assertEqual(self.new('foo')['Mode'], '100644') -- cgit v1.2.1