django-timedelta-field

PostgreSQL can store data as INTERVAL type, which is close to meaning the
same as python's timedelta object (although better in a couple of ways).

I have lots of use for timedelta objects, and having code that basically
wrapped integer objects as a number of seconds was common. This module
combines the two:

a timedelta.TimedeltaField() object that transparently converts
to and from datetime.timedelta

storage of the data as an INTERVAL in PostgreSQL, or a string in
other databases. (Other databases will be considered if I ever
use them, or receive patches).

The coolest part of this package is the way it manipulates strings entered
by users, and presents them. Any string of the format:

[X weeks,] [Y days,] [Z hours,] [A minutes,] [B seconds]

will be converted to a timedelta object. Even shortened versions can be used:
hrs, hr or h will also suffice. The parsing ignores trailing 's', but is
smart about adding them in when presenting the data to the user.

Todo

Handle strings with times in other languages. I'm not really sure about how
to do this, but it may be useful.

Changelog

0.6.7: Added LICENSE file.

0.6.6: Add in a couple of new template filters: total_seconds, and total_seconds_sort.

The latter zero-pads the value to 10 places, ideal for lexical sorting.
This correctly sorts timedeltas of up to around 10 years, if you need more
you can pass an argument to the filter.

0.6.5: Empty string values in database now are returned as None for the field value.

Note that you must have field.null=True to store a NULL in the db.
I'm still not 100% happy with this: postgres may choke on empty string values when doing INTERVAL comparisons.
Thanks to Gustavo Dias jaimes and reidpr for the report/fix.

0.6.4: Correctly parse '1w' (previously required 1wk).

Don't parse things like '1 hs', require '1 hrs'.
Test a bit harder.

0.6.3: Correctly parse '1h' as one hour (previously required 1hr).

0.6.2: Remember to include VERSION number.

0.6.0: Added total_seconds helper (for python < 2.7)

0.5.3: Include long_description from this file.

0.5.2: Added decimal_percentage, which gives us a decimal.Decimal object.