-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datetime and timedelta #510
Comments
There is not such thing right now but it would be interesting. |
Is this the use case? ureg = UnitRegistry()
t = ureg.Quantity(datetime.timedelta(days=4))
str(t)
'4.0 day' |
I guess that is more in the direction of interoperating datetime objects with currently supported units such as: >>> # Currently possible
>>> 4 * ureg.hour
<Quantity(4, 'hour')>
>>> 4 * ureg.hour + 30 * ureg.min
<Quantity(4.5, 'hour')>
>>> # Not possible now
>>> datetime.datetime.now() + 4 * ureg.hour |
Yes exactly. I don't think its an easy problem to solve as there are a lot of nuances with dates and times, but as long it is was properly defined/documented it would be interesting. python-dateutil has some interesting solutions. |
I think we can start by providing a conversion utility between quantity and timedelta |
Not sure if it's a good idea, but you could also put |
I was exploring a bit and wrote a conversion between timedelta and quantity. I'll try hooking it up in the math ops and see what happens. This is an interesting issue! |
I think that date rules are very similar to our offset units:
and that Pint Quantities are conceptualy timedeltas. What do you think? |
I agree that Pint quantities are conceptually timedeltas. Would it be as simple as adding something like this method to _Quantity and calling it appropriately from __add__, __sub__, etc. when the other side is a datetime? def to_timedelta(self):
return datetime.timedelta(microseconds=self.to('microseconds').magnitude) I can make a PR with these changes if this seems right. |
Sounds good to me. |
This is implemented in 0.8.1. Let's see how it plays out. |
Can pint support determining units from a timedelta? It would be useful if it could for dealing with raw data.
The text was updated successfully, but these errors were encountered: