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

Support for negative timedeltas #23

Open
Serfentum opened this issue Apr 7, 2020 · 1 comment
Open

Support for negative timedeltas #23

Serfentum opened this issue Apr 7, 2020 · 1 comment

Comments

@Serfentum
Copy link

Hi! Thank you for your library, I just wanna know is it likely that you will add support for negative deltas? For example

timeparse('-1 days -00:00:14.513431')

gives None, why it would be nice (at least for my purpose) to get negative number of seconds in this delta. Probably also output should be the same for such input

timeparse('-1 days 00:00:14.513431')

It's not crucial and could be circumvented of course, but would be nice to have it from the box, thank you)

@SGmuwa
Copy link

SGmuwa commented Apr 18, 2021

from pytimeparse.timeparse import timeparse
from datetime import timedelta

t = timedelta(days= -1, seconds=5)
print(t) # -1 day, 0:00:05
t = timedelta(seconds=timeparse(str(t)))
print(t) # -2 days, 23:59:55
t = timedelta(seconds=timeparse(str(t)))
print(t) # -3 days, 0:00:05

t = timedelta(days= -1, seconds=-5)
print(t) # -2 days, 23:59:55
t = timedelta(seconds=timeparse(str(t)))
print(t) # -3 days, 0:00:05
t = timedelta(seconds=timeparse(str(t)))
print(t) # -4 days, 23:59:55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants