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: Subtraction #35

Closed bramski closed 3 years ago

bramski commented 3 years ago

Hello @thombashi

I have need for a feature in this repository. I will either build it into our app or I can build it in this repository.

I need to implement subtraction. This is intersection, and then removal of the intersected region. It would return an array of ranges as the result.

range.subtract(x) => [] # Where range.intersect(x) is the same or larger range than the original
range.subtract(x) => [new_range] # One range is returned if the second range reaches the end or beginning of the original
range.subtract(x) => [new_range1, new_range2] # Two ranges are returned if the intersection is entirely within the original range and the result of the subtraction should slice the original range in two

What do you think? Let me know I need to implement this feature tomorrow. Cheers.

thombashi commented 3 years ago

Hello @bramski

The subtract method looks useful.

A pull request would be welcome.

bramski commented 3 years ago

Implemented by: https://github.com/thombashi/DateTimeRange/pull/36

thombashi commented 3 years ago

Merged #36

bramski commented 3 years ago

🙏 Thanks so much for the merge and speedy release @thombashi !