diff options
| author | Scott Gasch <[email protected]> | 2021-09-22 17:37:17 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-22 17:37:17 -0700 |
| commit | 5e1bced276766fec9d4c408790c99d4a26d267e0 (patch) | |
| tree | c2302bab0e1ccf48e599edacc5b9f1696c73acfe /datetime_utils.py | |
| parent | af108975dcae3fe59d1b7db6f7f8a3dd3c7c0045 (diff) | |
Various little changes. Naming. Durations as arguments.
Diffstat (limited to 'datetime_utils.py')
| -rw-r--r-- | datetime_utils.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/datetime_utils.py b/datetime_utils.py index db5b2b5..c100057 100644 --- a/datetime_utils.py +++ b/datetime_utils.py @@ -652,6 +652,18 @@ def describe_duration(seconds: int, *, include_seconds = False) -> str: return descr +def describe_timedelta(delta: datetime.timedelta) -> str: + """ + Describe a duration represented by a timedelta object. + + >>> d = datetime.timedelta(1, 600) + >>> describe_timedelta(d) + '1 day, and 10 minutes' + + """ + return describe_duration(delta.total_seconds()) + + def describe_duration_briefly(seconds: int, *, include_seconds=False) -> str: """ Describe a duration briefly. @@ -685,6 +697,18 @@ def describe_duration_briefly(seconds: int, *, include_seconds=False) -> str: return descr.strip() +def describe_timedelta_briefly(delta: datetime.timedelta) -> str: + """ + Describe a duration represented by a timedelta object. + + >>> d = datetime.timedelta(1, 600) + >>> describe_timedelta_briefly(d) + '1d 10m' + + """ + return describe_duration_briefly(delta.total_seconds()) + + if __name__ == '__main__': import doctest doctest.testmod() |
