changeset 4773:8ab5d7d63191

Fixed issue2550802: Fixed date so second fraction can't cause rounding to 60.000 when serialising. Report and fix by Erik Hanspers.
author Bernhard Reiter <bernhard@intevation.de>
date Fri, 22 Mar 2013 12:09:12 +0100
parents cf22ac054c08
children 3adff0fb0207
files CHANGES.txt roundup/date.py
diffstat 2 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Fri Mar 15 15:19:53 2013 +0530
+++ b/CHANGES.txt	Fri Mar 22 12:09:12 2013 +0100
@@ -37,6 +37,8 @@
   when nuking (anatoly techtonik)
 - demo.py changing hostname in config.ini actually changes the address
   where demo.py listens. (John Rouillard)
+- issue2550802: Fixed date so second fraction can't cause rounding to
+  60.000 when serialising. Report and fix by Erik Hanspers. (Bernhard Reiter)
 
 2012-12-21: 1.4.21
 
--- a/roundup/date.py	Fri Mar 15 15:19:53 2013 +0530
+++ b/roundup/date.py	Fri Mar 22 12:09:12 2013 +0100
@@ -274,7 +274,8 @@
                 self.second = _local_to_utc(y, m, d, H, M, S, offset)
             # we lost the fractional part
             self.second = self.second + frac
-            if str(self.second) == '60.0': self.second = 59.9
+            # making sure we match the precision of serialise()
+            self.second = min(self.second, 59.999)
         except:
             raise ValueError, 'Unknown spec %r' % (spec,)
 
@@ -543,6 +544,13 @@
             self.second, 0, 0, 0)
 
     def serialise(self):
+        """ Return serialised string for self's datetime.
+
+        Uses '%06.3f' as format for self.second, which therefor
+        must be <=59.999 to work. Otherwise it will be rounded
+        to 60.000.
+
+        """
         return '%04d%02d%02d%02d%02d%06.3f'%(self.year, self.month,
             self.day, self.hour, self.minute, self.second)
 

Roundup Issue Tracker: http://roundup-tracker.org/