Skip to content

Commit 0690757

Browse files
Fixed issue2550802: Fixed date so second fraction can't cause rounding to
60.000 when serialising. Report and fix by Erik Hanspers.
1 parent 02a73db commit 0690757

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Fixed:
3737
when nuking (anatoly techtonik)
3838
- demo.py changing hostname in config.ini actually changes the address
3939
where demo.py listens. (John Rouillard)
40+
- issue2550802: Fixed date so second fraction can't cause rounding to
41+
60.000 when serialising. Report and fix by Erik Hanspers. (Bernhard Reiter)
4042

4143
2012-12-21: 1.4.21
4244

roundup/date.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ def __init__(self, spec='.', offset=0, add_granularity=False,
274274
self.second = _local_to_utc(y, m, d, H, M, S, offset)
275275
# we lost the fractional part
276276
self.second = self.second + frac
277-
if str(self.second) == '60.0': self.second = 59.9
277+
# making sure we match the precision of serialise()
278+
self.second = min(self.second, 59.999)
278279
except:
279280
raise ValueError, 'Unknown spec %r' % (spec,)
280281

@@ -543,6 +544,13 @@ def get_tuple(self):
543544
self.second, 0, 0, 0)
544545

545546
def serialise(self):
547+
""" Return serialised string for self's datetime.
548+
549+
Uses '%06.3f' as format for self.second, which therefor
550+
must be <=59.999 to work. Otherwise it will be rounded
551+
to 60.000.
552+
553+
"""
546554
return '%04d%02d%02d%02d%02d%06.3f'%(self.year, self.month,
547555
self.day, self.hour, self.minute, self.second)
548556

0 commit comments

Comments
 (0)