Monday, 4 October 2021

Split up datetime interval according to labeled partition of a week

I have shift which is a datetime interval (a pair of datetimes). My weeks have a labeled partition (every week is the same: divided into parts, and each part has a label). I want to split up shift into labeled parts (i.e. into several subintervals), according to the partition of the week.

Example. Suppose shift is the interval 2019-10-21 18:30 - 2019-10-22 08:00, and the partition of the week is as follows: Monday to Friday 07:00 - 19:00 has label A, and the rest of the week has label B. In this case the splitting of shift should be the following list of labeled subintervals:

  • 2019-10-21 18:30 - 2019-10-21 19:00 with label A,
  • 2019-10-21 19:00 - 2019-10-22 07:00 with label B, and
  • 2019-10-22 07:00 - 2019-10-22 08:00 with label A.

How do I do this in general?

Input: a datetime interval (pair), and a labeled partition of the week (how to best represent this?)

Output: a list of labeled datetime intervals (pairs).



from Split up datetime interval according to labeled partition of a week

No comments:

Post a Comment