Skip to content

Commit 31f640c

Browse files
committed
Merge branch 'pr/glaslos/5'
2 parents 5300644 + c59c01f commit 31f640c

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

openhours.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ func merge4(o ...time.Time) (bool, []time.Time) {
244244

245245
func merge(o []time.Time) []time.Time {
246246
sort.SliceStable(o, func(i, j int) bool {
247+
if o[i].Day() == o[j].Day() {
248+
return o[i].Hour() < o[j].Hour()
249+
}
247250
return o[i].Day() < o[j].Day()
248251
})
249252
for i := 0; i < len(o); i += 2 {

openhours_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,16 @@ func TestNew(t *testing.T) {
231231
{"complex = simple", "su-sa 00:00-12:00,12:00-24:00", l, NewMust("", l)},
232232
{"complex = simple", "su-sa 00:00-12:00;su-sa 12:00-24:00", l, NewMust("", l)},
233233
{"time windows order does not matter anymore", "mo-su 00:00-24:00", l, NewMust("", l)},
234-
{"weird times in same sentence", "mo-fr 00:00-15:00,10:00-24:00", l, NewMust("mo-fr 00:00-24:00", l)},
235-
{"weird times in same sentence one contained", "mo-fr 10:00-15:00,00:00-24:00", l, NewMust("mo-fr 00:00-24:00", l)},
236-
{"weird times in different sentence", "mo-fr 00:00-15:00;mo-fr 10:00-24:00", l, NewMust("mo-fr 00:00-24:00", l)},
237-
{"weird times in different sentence contained", "mo-fr 10:00-15:00;mo-fr 00:00-24:00", l, NewMust("mo-fr 00:00-24:00", l)},
238-
{"total chaos", "tu-fr 10:00-15:00;mo 08:00-09:00;mo-fr 00:00-24:00", l, NewMust("mo-fr 00:00-24:00", l)},
239234
{"one day", "mo 10:00-15:00", l, []time.Time{newDate(1, 10, 0, 0, 0, l), newDate(1, 15, 0, 0, 0, l)}},
240235
{"two days", "mo 10:00-15:00;fr 08:00-14:00", l, []time.Time{newDate(1, 10, 0, 0, 0, l), newDate(1, 15, 0, 0, 0, l), newDate(5, 8, 0, 0, 0, l), newDate(5, 14, 0, 0, 0, l)}},
236+
{"week with break", "Tu-Th 10:30-13:00,14:00-24:00", l, []time.Time{
237+
newDate(2, 10, 30, 0, 0, l), newDate(2, 13, 0, 0, 0, l),
238+
newDate(2, 14, 0, 0, 0, l), newDate(2, 24, 0, 0, 0, l),
239+
newDate(3, 10, 30, 0, 0, l), newDate(3, 13, 0, 0, 0, l),
240+
newDate(3, 14, 0, 0, 0, l), newDate(3, 24, 0, 0, 0, l),
241+
newDate(4, 10, 30, 0, 0, l), newDate(4, 13, 0, 0, 0, l),
242+
newDate(4, 14, 0, 0, 0, l), newDate(4, 24, 0, 0, 0, l),
243+
}},
241244
}
242245
for _, tt := range tests {
243246
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)