Last active
June 29, 2018 10:38
-
-
Save cypreess/e7dd79ebb81ed31e392809527a34ec25 to your computer and use it in GitHub Desktop.
Formatting negative timedelta in more natural way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def timedelta_to_string(timedelta): | |
total_seconds = timedelta.total_seconds() | |
if total_seconds < 0: | |
timedelta_str = '-' + str(datetime.timedelta() - timedelta) | |
else: | |
timedelta_str = '+' + str(timedelta) | |
return timedelta_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment