jackc / tod

Time of day and shift types for Ruby
MIT License
435 stars 56 forks source link

Add merge method on Shift class #67

Open doei opened 5 years ago

doei commented 5 years ago

Hi, This isn't much but I thought it could be handy. Thanks for reviewing :)

jackc commented 5 years ago

This is an interesting idea. But there are some edge cases that aren't covered -- and they might be difficult to resolve.

  1. Discontinuous shifts - What is the result of merging 7AM-9AM and 10AM-11AM? I would think it would need to be an invalid operation.
  2. Shifts crossing midnight - What is the result of merging 10PM-2AM and 1AM-3AM? I would expect 10PM-3AM but the current code would result in 1AM-10PM.
  3. Shifts that combine to over 24 hours - This problem overlaps with the previous. What does it mean to merge 1PM-5AM with 4AM-3PM? I would expect this to resolve to 1PM to 3PM the next day - a 26 hour shift. But the shift class can't represent that.