johnpaulett / django-durationfield

Temporary reusable Django application for adding a DurationField, until Django issue #2443 is resolved.
http://django-durationfield.readthedocs.org
67 stars 24 forks source link

Fix for correctly working with microseconds #13

Closed troygrosfield closed 10 years ago

troygrosfield commented 10 years ago

Fixes #12.

troygrosfield commented 10 years ago

I've tested this changes locally as well and everything's working as expected after this fix.

troygrosfield commented 10 years ago

Any updates on this?

johnpaulett commented 10 years ago

The implementation looks fairly complicated (multiple len, a strip, math). Any reason not to just do int(time_groups[key].ljust(6, '0'))?

If that works, perhaps we can refactor to only have theint() call once, something like:

value = time_groups[key]
if key == 'microseconds':
    value = value.ljust(6, '0')
time_groups[key] = int(value)

If you also would not mind, it would be nice to add a simple comment explaining why the padding occurs (e.g. to represent as a microsecond, since not all digits are required)

troygrosfield commented 10 years ago

Done. Also, would recommend bumping travis ci to build against the last django version (1.6.0 -> 1.6.2)