thombashi / DateTimeRange

DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.
https://datetimerange.rtfd.io/
MIT License
106 stars 16 forks source link

[Feature request] Add a method to return the length of the range #33

Closed momocow closed 4 years ago

momocow commented 4 years ago

Maybe a method that returns a timedelta is enough to represent the length of the range.

thombashi commented 4 years ago

@momocow Thank you for your feedback.

You can get a datetime.timedelta instance of the range by timedelta property from a DateTimeRange instance: https://datetimerange.readthedocs.io/en/latest/pages/reference/datetimerange.html#datetimerange.DateTimeRange.timedelta

Or you can get total seconds by get_timedelta_second method: https://datetimerange.readthedocs.io/en/latest/pages/reference/datetimerange.html#datetimerange.DateTimeRange.get_timedelta_second

Is this what you would expect?

momocow commented 4 years ago

Oops, yes! I must miss reading this part of the API, I should check it out more carefully.

Thank you for the links and also a nice library that fits my requirements!