Open jgsogo opened 11 years ago
I was unaware of the ISO 8601 Duration specification. A patch that added support for IS0 8601 and related tests would be very welcomed. Probably involves altering str_to_timedelta.
For backwards compatibility, we would want to still support the existing duration syntax.
It seems that isodate [1] or dateutil [2] should do the trick, working with strptime would be so hazardous. I'll try to work on it this week
[1] https://pypi.python.org/pypi/isodate [2] http://labix.org/python-dateutil
I looked into it, as I desperately need an implementation of ISO 8601 durations. Sadly you decided to work with pythons datetime.timedelta
which is a poor implementation of a duration.
The only way I see to make this happening is, changing your to_python
to an object that inherits from timedelta
but implements a isoformat()
as datetime
does it self. This would be downwards compatible, but has one big disadvantage.
timedelta
is not a duration. A duration can't be negative by definition, a timedelta can. The cleaner approach would be implementing a real duration and using an UNSIGNED BIGINT
your database.
I would be will to implement this if you'd be cool with that little change.
@codingjoe -- I'm trying to understand your use case. Are you looking for:
I would completely welcome a patch for the first item. I think the leading "P" of an ISO8601 duration should make detecting it straightforward in str_to_timedelta.
The second item may be currently accomplishable with the isodate library (duration_isoformat
can take a timedelta
).
I won't argue that perhaps a better name for this library currently is IntervalField (essentially it provides PostgreSQL's INTERVAL across various database backends) or TimedeltaField. However, I believe using form & model validators you could enforce only positive durations using this library currently.
Definitely some opportunity for improvement, but I'm just trying to grasp exactly what you are looking for.
@johnpaulett sorry for my confusing post.
Here's what I'm up to: I currently writing a django implementation of mircodata objects as defined on http://schema.org/
That requires a ISO duration. I know that integers are more practical for machine use, but they suck as a service to service interface. I find it a little sad, that durations aren't implemented in python itself.
I didn't know that this library intends to implement a PostgreSQL Interval. PostgreSQL has a confusing naming there as well. In ISO an interval is DateTime+Duration.
I think I'm going to write a patch for 2. if that's cool with you. It looks like 1. is already implemented in str_to_timedelta
To be clear, 1 is not available in str_to_timedelta
currently, but I would welcome a patch for it.
Regarding 2, would have to see code a bit more, not 100% sure if this is something this library should provide or if a more widely applicable item for all timedeltas in Python.
It's not my number one priority. It's more a long shot, of a library want to develop to maybe use it later commercially. In other words it's gonna take me a while. But I'll keep you posted on developments and i'll supply patches if need be.
@jnelson I would steer away from including a GPL-licensed dependency (aniso8601) for this BSD-licensed library.
Sorry I didn't catch that. Looks like isodate is also BSD, so that's easy. Thanks!
(Thinking about machines and importing data)
There is an standard about how to express durations, ISO8601 [1], it would be interesting to allow this format as input, although maintain as output both, ISO8601 and the more readable one (current).
[1] http://en.wikipedia.org/wiki/ISO_8601#Durations