Skip to content
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

Add add_py_delta method? #177

Open
hongquan opened this issue Oct 19, 2024 · 3 comments
Open

Add add_py_delta method? #177

hongquan opened this issue Oct 19, 2024 · 3 comments
Labels
discussion Discussion is needed before proceeding

Comments

@hongquan
Copy link

Because add can accept DateDelta / TimeDelta, I think it would be nice it has add_py_delta to accept std timedelta object. Otherwise, we have to convert it to whenever types before passing to add, which makes code verbose.

@ariebovenberg
Copy link
Owner

Hi @hongquan, thanks for posting this issue. Interesting idea. Although, instead of a new method, it'd be cleaner to simply make add() support timedelta. I don't have many issues with this, as timedelta and TimeDelta are very similar and this could ease migration from the standard library.

Out of curiousity—do you need this because you're migrating away from datetime, or do you have a different use case?

@ariebovenberg ariebovenberg added the discussion Discussion is needed before proceeding label Oct 19, 2024
@hongquan
Copy link
Author

@ariebovenberg I have this need because I have Django application, where all timedelta is read from PostgreSQL as std timedelta object.

@ariebovenberg
Copy link
Owner

Thanks for the context. Seems like a common use case.

Agree that it reduces noise in the code quite a bit:

dt.add(delta)
# vs
dt.add(TimeDelta.from_py_timedelta(delta))

One concern I do have is that dt.add(days=1) is in some cases not the same as dt.add(timedelta(days=1)), because the latter always assumes days are exactly 24 hours (which is not the case during DST transitions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussion is needed before proceeding
Projects
None yet
Development

No branches or pull requests

2 participants