From 8e918168ae60f8fdbab64f697776e914e3bb5d44 Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 17 Oct 2023 20:30:21 -0700 Subject: [PATCH 1/2] Fix the modified property --- plone/namedfile/file.py | 2 +- plone/namedfile/tests/test_blobfile.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plone/namedfile/file.py b/plone/namedfile/file.py index 36dd30b2..ae50723d 100644 --- a/plone/namedfile/file.py +++ b/plone/namedfile/file.py @@ -75,7 +75,7 @@ class ModifiedPropertyMixin: @property def modified(self): if hasattr(self, "_modified"): - return self._modified + return self._modified / 1000 # Fall back to modification time in database. return self._p_mtime diff --git a/plone/namedfile/tests/test_blobfile.py b/plone/namedfile/tests/test_blobfile.py index 67f7107b..30d32b31 100644 --- a/plone/namedfile/tests/test_blobfile.py +++ b/plone/namedfile/tests/test_blobfile.py @@ -81,19 +81,19 @@ def testModifiedTimeStamp(self): image = self._makeImage() old_timestamp = image.modified time.sleep(1/1000) # make sure at least 1ms passes + now = DateTime() + self.assertGreater(now, DateTime(old_timestamp)) image._setData(zptlogo) self.assertNotEqual(image.modified, old_timestamp) def testFallBackToDatabaseModifiedTimeStamp(self): dt = DateTime() image = MockNamedBlobImage() - image._p_mtime = dt.millis() + image._p_mtime = int(dt) image._modified = (dt + 1).millis() delattr(image, "_modified") - marker = object() - self.assertEqual(marker, getattr(image, "_modified", marker)) - self.assertEqual(dt.millis(), image._p_mtime) + self.assertEqual(image.modified, image._p_mtime) def testInterface(self): self.assertTrue(INamedBlobImage.implementedBy(NamedBlobImage)) From 1a7588449bf21a6cb6d7a87933a370cf4052bd2c Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 17 Oct 2023 20:36:04 -0700 Subject: [PATCH 2/2] changelog --- news/153.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/153.bugfix diff --git a/news/153.bugfix b/news/153.bugfix new file mode 100644 index 00000000..f3d26eb4 --- /dev/null +++ b/news/153.bugfix @@ -0,0 +1 @@ +Fix calculation of file modification time. @davisagli