spatie/opening-hours

Overflow support does not seem to work for createAndMergeOverlappingRanges

willrp opened this issue · 2 comments

Hello.
First of all I would like to appreciate this library, great work.
I decided to post here to maybe be fixed or others to be aware of it.

"version": "2.13.0"

The method createAndMergeOverlappingRanges seems to not respect the attribute overflow.
Steps to reproduce the issue:

  1. Use the array in the code below to create an object with createAndMergeOverlappingRanges
  2. Check that overflow is still false.

Obs: It works with the create method normally.

Data used to create the object with createAndMergeOverlappingRanges:
array:8 [
  "monday" => []
  "tuesday" => []
  "wednesday" => array:2 [
    0 => "09:00-12:00"
    1 => "13:00-18:00"
  ]
  "thursday" => array:2 [
    0 => "09:00-12:00"
    1 => "13:00-18:00"
  ]
  "friday" => array:2 [
    0 => "09:00-12:00"
    1 => "13:00-18:00"
  ]
  "saturday" => array:2 [
    0 => "09:00-12:00"
    1 => "13:00-18:00"
  ]
  "sunday" => array:2 [
    0 => "09:00-12:00"
    1 => "13:00-18:00"
  ]
  "overflow" => true
]

Object made from the data above:
Spatie\OpeningHours\OpeningHours^ {#1859 // tests/Models/OpeningPolicyTest.php:26
  #openingHours: array:7 [
    "monday" => Spatie\OpeningHours\OpeningHoursForDay^ {#1856
      #openingHours: []
      #data: null
    }
    "tuesday" => Spatie\OpeningHours\OpeningHoursForDay^ {#1888
      #openingHours: []
      #data: null
    }
    "wednesday" => Spatie\OpeningHours\OpeningHoursForDay^ {#1884
      #openingHours: array:2 [
        0 => Spatie\OpeningHours\TimeRange^ {#2583
          #start: Spatie\OpeningHours\Time^ {#2693
            #hours: 9
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2691
            #hours: 12
            #minutes: 0
            #data: null
          }
          #data: null
        }
        1 => Spatie\OpeningHours\TimeRange^ {#2631
          #start: Spatie\OpeningHours\Time^ {#2582
            #hours: 13
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2584
            #hours: 18
            #minutes: 0
            #data: null
          }
          #data: null
        }
      ]
      #data: null
    }
    "thursday" => Spatie\OpeningHours\OpeningHoursForDay^ {#2700
      #openingHours: array:2 [
        0 => Spatie\OpeningHours\TimeRange^ {#2634
          #start: Spatie\OpeningHours\Time^ {#2703
            #hours: 9
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2682
            #hours: 12
            #minutes: 0
            #data: null
          }
          #data: null
        }
        1 => Spatie\OpeningHours\TimeRange^ {#2580
          #start: Spatie\OpeningHours\Time^ {#2579
            #hours: 13
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2578
            #hours: 18
            #minutes: 0
            #data: null
          }
          #data: null
        }
      ]
      #data: null
    }
    "friday" => Spatie\OpeningHours\OpeningHoursForDay^ {#2687
      #openingHours: array:2 [
        0 => Spatie\OpeningHours\TimeRange^ {#2577
          #start: Spatie\OpeningHours\Time^ {#2576
            #hours: 9
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2570
            #hours: 12
            #minutes: 0
            #data: null
          }
          #data: null
        }
        1 => Spatie\OpeningHours\TimeRange^ {#2568
          #start: Spatie\OpeningHours\Time^ {#2569
            #hours: 13
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2575
            #hours: 18
            #minutes: 0
            #data: null
          }
          #data: null
        }
      ]
      #data: null
    }
    "saturday" => Spatie\OpeningHours\OpeningHoursForDay^ {#2679
      #openingHours: array:2 [
        0 => Spatie\OpeningHours\TimeRange^ {#2574
          #start: Spatie\OpeningHours\Time^ {#2573
            #hours: 9
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2572
            #hours: 12
            #minutes: 0
            #data: null
          }
          #data: null
        }
        1 => Spatie\OpeningHours\TimeRange^ {#2571
          #start: Spatie\OpeningHours\Time^ {#2567
            #hours: 13
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2566
            #hours: 18
            #minutes: 0
            #data: null
          }
          #data: null
        }
      ]
      #data: null
    }
    "sunday" => Spatie\OpeningHours\OpeningHoursForDay^ {#2697
      #openingHours: array:2 [
        0 => Spatie\OpeningHours\TimeRange^ {#2701
          #start: Spatie\OpeningHours\Time^ {#2699
            #hours: 9
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2555
            #hours: 12
            #minutes: 0
            #data: null
          }
          #data: null
        }
        1 => Spatie\OpeningHours\TimeRange^ {#2696
          #start: Spatie\OpeningHours\Time^ {#2591
            #hours: 13
            #minutes: 0
            #data: null
          }
          #end: Spatie\OpeningHours\Time^ {#2590
            #hours: 18
            #minutes: 0
            #data: null
          }
          #data: null
        }
      ]
      #data: null
    }
  ]
  #exceptions: []
  #filters: []
  #timezone: null
  #outputTimezone: null
  #overflow: false
  #dayLimit: null
  #dateTimeClass: "DateTime"
  #data: null
}

In the createAndMergeOverlappingRanges it is stated that the overflow attribute is supported.

Thank you in advance. Cheers.
Thanks for the great library.

If someone has the same problem, I made a work around like this:

$array = THE NORMAL DATA TO CREATE THE OBJECT;
$data = OpeningHours::mergeOverlappingRanges($array);
$data['overflow'] = true;
$opening_hours = OpeningHours::create($data);

The method mergeOverlappingRanges drops the overflow attribute.

Cheers

Hello, indeed mergeOverlappingRanges() will ignore and drop the overflow flag. Also the behavior with overflow was not tested, so I'm not sure if it behaves properly when having merging schedules that both have night overflow.