Closed troygrosfield closed 10 years ago
Patches welcome. However, even if using django-durationfield, since it returns a datetime.timedelta
instance, you could use django-timedeltafield's tag, since it just consumes datetime.timedelta
Fair enough. However, I didn't want to add another dependency if possible which is why I'd rather have it in this lib. I'll play around with it a bit.
Also, this might be worth opening another ticket, but in the example above:
>>> my_object = MyObject.objects.create(duration='0:03:58.16')
>>> my_object.duration
0:03:58.000016
I guess I would see that as "3 minutes and 58.16 seconds" which isn't how it gets evaluated. I guess I would expect to see:
>>> my_object = MyObject.objects.create(duration='0:03:58.16')
>>> my_object.duration
0:03:58.16
.16 seconds == 160 milliseconds == 160000 microseconds
Timedelta uses microseconds, not milliseconds which is what I think the issue is? When I go to add a duration to a form field field and add the value:
0:03:58.16
Then, when I go to edit that same value, the default value is:
0:03:58.000016
Which isn't correct. Would you like me to submit the pull request for this?
@troygrosfield Good catch. Looks like the microsecond parsing does int(16)
instead of int(160000)
Please submit a pull request.
Looks like it's the regular expression in:
time_format = r"(?:(?P<weeks>\d+)\W*(?:weeks?|w),?)?\W*(?:(?P<days>\d+)\W*(?:days?|d),?)?\W*(?:(?P<hours>\d+):(?P<minutes>\d+)(?::(?P<seconds>\d+)(?:\.(?P<microseconds>\d+))?)?)?"
The "microseconds" should be "milliseconds".
Please add appropriate test cases too. We definitely still want to support microseconds (0:03:58.000016).
Create a template tag that format the timedelta to a friendly display. Right now if you call the string representation for the duration field you get:
For template formatting, something like:
That outputs:
or even:
Something similar to what's going on here: