DateTimeRange (v2.3.2) is a Python library designed to handle operations on time ranges, such as checking time inclusion, finding intersections, truncating, and iterating through ranges. It is actively maintained with frequent updates and supports modern Python versions.
pip install datetimerangeVerified import paths — ran on the pinned version, not inferred.
Initializes a DateTimeRange object, demonstrates checking for time inclusion, and calculates the intersection with another range. It's crucial to ensure consistent timezone awareness for accurate comparisons.
Upgrade your Python interpreter to 3.9 or a newer version (e.g., `pyenv install 3.9.18 && pyenv global 3.9.18`).
Upgrade to v2.3.0 or later to benefit from improved timezone handling. Always provide explicit timezone information when creating `datetime` objects or `DateTimeRange` instances to prevent unexpected behavior. Use the `timezone` argument in the constructor where available (added in v2.2.0).
Be explicit with `intersection_threshold` when computing intersections, especially for boundary cases, to match desired behavior. Review the documentation for its exact usage.
Ensure `start_datetime` and `end_datetime` have consistent timezone information, or explicitly set the `timezone` argument during `DateTimeRange` instantiation or using `set_time_range` if your version supports it (v2.2.0+). Example: `DateTimeRange(dt1.astimezone(pytz.utc), dt2.astimezone(pytz.utc))`.
Upgrade the `datetimerange` library to the latest version using `pip install --upgrade datetimerange` to access new features and bug fixes.
Ensure that any datetime strings passed to `DateTimeRange` or its methods conform to expected formats. If using `start_time_format` or `end_time_format`, confirm they correctly match your input strings. Upgrade to v2.3.2 or later to benefit from improved `ValueError` handling in formatting methods.