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

Does not raise ValueError for input like "invalid" #11

Closed blueyed closed 10 years ago

blueyed commented 10 years ago

I would have expected to see validation errors, in case of input like "invalid", but it gets handled as / converted to 0.

This is most likely, because str_to_timedelta('invalid') does not raise an exception.

Also, "86400" should either gets handled as seconds (resulting in one day), or also raise an exception / validation error,

johnpaulett commented 10 years ago

Thanks @blueyed! Patch for the invalid strings.

However, I'm hesitant to assume that an arbitrary integer represents the number of seconds. If there is strong justification for it, let me know, but perhaps if an application knows it will be receiving seconds, you could simply pass timedelta(seconds=int("86400")) to the DurationField.