changeset f9bcec80ea36 in tryton:5.0 details: https://hg.tryton.org/tryton?cmd=changeset;node=f9bcec80ea36 description: Convert to float when parsing timedelta
The user can enter a float value for the converter parts. issue8816 review256231002 (grafted from 9adf3642e423d88d3b7ab373d05a402dd0e331a7) diffstat: tryton/common/timedelta.py | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diffs (53 lines): diff -r 281a8af1b68d -r f9bcec80ea36 tryton/common/timedelta.py --- a/tryton/common/timedelta.py Fri Nov 08 19:22:02 2019 +0100 +++ b/tryton/common/timedelta.py Sat Nov 16 12:51:50 2019 +0100 @@ -86,7 +86,7 @@ for t, v in zip(part.split(':'), [converter['h'], converter['m'], converter['s']]): try: - seconds += abs(float(t)) * v + seconds += abs(locale.atof(t)) * v except ValueError: pass else: @@ -94,13 +94,13 @@ if part.endswith(separator): part = part[:-len(separator)] try: - seconds += abs(int(part)) * converter[key] + seconds += abs(locale.atof(part)) * converter[key] except ValueError: pass break else: try: - seconds += abs(float(part)) + seconds += abs(locale.atof(part)) except ValueError: pass @@ -135,14 +135,23 @@ _tests_parse = [ (datetime.timedelta(), ' '), (datetime.timedelta(), 'foo'), - (datetime.timedelta(), '1.5d'), + (datetime.timedelta(days=1.5), '1.5d'), (datetime.timedelta(days=-2), '1d -1d'), (datetime.timedelta(hours=1, minutes=5, seconds=10), '1:5:10:42'), (datetime.timedelta(hours=2), '1: 1:'), (datetime.timedelta(hours=.25), ':15'), + (datetime.timedelta(hours=1), '1h'), + (datetime.timedelta(hours=.25), '.25h'), ] def test_parse(): for timedelta, text, in _tests + _tests_parse: assert parse(text) == timedelta + + +if __name__ == '__main__': + for name in list(globals()): + if name.startswith('test_'): + func = globals()[name] + func()