@@ -956,6 +956,158 @@ public function testConflicts()
956
956
957
957
}
958
958
959
+ public function testPartialOverlaps ()
960
+ {
961
+ $ entity1 = new Availability ([
962
+ 'id ' => '1 ' ,
963
+ 'weekday ' => ['monday ' => '2 ' ],
964
+ 'startDate ' => strtotime ('2024-01-15 ' ),
965
+ 'endDate ' => strtotime ('2024-01-15 ' ),
966
+ 'startTime ' => '08:00:00 ' ,
967
+ 'endTime ' => '12:00:00 ' ,
968
+ 'type ' => 'appointment ' ,
969
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
970
+ ]);
971
+
972
+ // Test overlap at start
973
+ $ entity2 = new Availability ([
974
+ 'id ' => '2 ' ,
975
+ 'weekday ' => ['monday ' => '2 ' ],
976
+ 'startDate ' => strtotime ('2024-01-15 ' ),
977
+ 'endDate ' => strtotime ('2024-01-15 ' ),
978
+ 'startTime ' => '07:00:00 ' ,
979
+ 'endTime ' => '09:00:00 ' ,
980
+ 'type ' => 'appointment ' ,
981
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
982
+ ]);
983
+
984
+ // Test overlap at end
985
+ $ entity3 = new Availability ([
986
+ 'id ' => '3 ' ,
987
+ 'weekday ' => ['monday ' => '2 ' ],
988
+ 'startDate ' => strtotime ('2024-01-15 ' ),
989
+ 'endDate ' => strtotime ('2024-01-15 ' ),
990
+ 'startTime ' => '11:00:00 ' ,
991
+ 'endTime ' => '13:00:00 ' ,
992
+ 'type ' => 'appointment ' ,
993
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
994
+ ]);
995
+
996
+ // Test completely contained
997
+ $ entity4 = new Availability ([
998
+ 'id ' => '4 ' ,
999
+ 'weekday ' => ['monday ' => '2 ' ],
1000
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1001
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1002
+ 'startTime ' => '09:00:00 ' ,
1003
+ 'endTime ' => '11:00:00 ' ,
1004
+ 'type ' => 'appointment ' ,
1005
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1006
+ ]);
1007
+
1008
+ $ list = new AvailabilityList ([$ entity1 , $ entity2 , $ entity3 , $ entity4 ]);
1009
+ $ conflicts = $ list ->checkAllVsExistingConflicts (
1010
+ new \DateTimeImmutable ('2024-01-15 00:00:00 ' ),
1011
+ new \DateTimeImmutable ('2024-01-15 23:59:59 ' )
1012
+ );
1013
+
1014
+ $ this ->assertEquals (6 , $ conflicts ->count (), "Should detect all overlaps bidirectionally " );
1015
+ }
1016
+
1017
+ public function testEdgeCaseOverlaps ()
1018
+ {
1019
+ // Test back-to-back times
1020
+ $ entity1 = new Availability ([
1021
+ 'id ' => '1 ' ,
1022
+ 'weekday ' => ['monday ' => '2 ' ],
1023
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1024
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1025
+ 'startTime ' => '08:00:00 ' ,
1026
+ 'endTime ' => '12:00:00 ' ,
1027
+ 'type ' => 'appointment ' ,
1028
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1029
+ ]);
1030
+
1031
+ $ entity2 = new Availability ([
1032
+ 'id ' => '2 ' ,
1033
+ 'weekday ' => ['monday ' => '2 ' ],
1034
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1035
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1036
+ 'startTime ' => '12:00:00 ' ,
1037
+ 'endTime ' => '16:00:00 ' ,
1038
+ 'type ' => 'appointment ' ,
1039
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1040
+ ]);
1041
+
1042
+ // Test overlap across midnight
1043
+ $ entity3 = new Availability ([
1044
+ 'id ' => '3 ' ,
1045
+ 'weekday ' => ['monday ' => '2 ' ],
1046
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1047
+ 'endDate ' => strtotime ('2024-01-16 ' ),
1048
+ 'startTime ' => '23:00:00 ' ,
1049
+ 'endTime ' => '01:00:00 ' ,
1050
+ 'type ' => 'appointment ' ,
1051
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1052
+ ]);
1053
+
1054
+ $ list = new AvailabilityList ([$ entity1 , $ entity2 , $ entity3 ]);
1055
+ $ conflicts = $ list ->checkAllVsExistingConflicts (
1056
+ new \DateTimeImmutable ('2024-01-15 00:00:00 ' ),
1057
+ new \DateTimeImmutable ('2024-01-16 23:59:59 ' )
1058
+ );
1059
+
1060
+ $ this ->assertEquals (0 , $ conflicts ->count (), "Back-to-back times should not be considered overlapping " );
1061
+ }
1062
+
1063
+ public function testWeekdayOverlaps ()
1064
+ {
1065
+ // Test same weekday, different weeks
1066
+ $ entity1 = new Availability ([
1067
+ 'id ' => '1 ' ,
1068
+ 'weekday ' => ['monday ' => '2 ' ],
1069
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1070
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1071
+ 'startTime ' => '08:00:00 ' ,
1072
+ 'endTime ' => '12:00:00 ' ,
1073
+ 'type ' => 'appointment ' ,
1074
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []],
1075
+ 'repeat ' => ['afterWeeks ' => '1 ' ]
1076
+ ]);
1077
+
1078
+ $ entity2 = new Availability ([
1079
+ 'id ' => '2 ' ,
1080
+ 'weekday ' => ['monday ' => '2 ' ],
1081
+ 'startDate ' => strtotime ('2024-01-22 ' ),
1082
+ 'endDate ' => strtotime ('2024-01-22 ' ),
1083
+ 'startTime ' => '08:00:00 ' ,
1084
+ 'endTime ' => '12:00:00 ' ,
1085
+ 'type ' => 'appointment ' ,
1086
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []],
1087
+ 'repeat ' => ['afterWeeks ' => '2 ' ]
1088
+ ]);
1089
+
1090
+ // Test different weekdays, same times
1091
+ $ entity3 = new Availability ([
1092
+ 'id ' => '3 ' ,
1093
+ 'weekday ' => ['tuesday ' => '3 ' ],
1094
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1095
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1096
+ 'startTime ' => '08:00:00 ' ,
1097
+ 'endTime ' => '12:00:00 ' ,
1098
+ 'type ' => 'appointment ' ,
1099
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1100
+ ]);
1101
+
1102
+ $ list = new AvailabilityList ([$ entity1 , $ entity2 , $ entity3 ]);
1103
+ $ conflicts = $ list ->checkAllVsExistingConflicts (
1104
+ new \DateTimeImmutable ('2024-01-15 00:00:00 ' ),
1105
+ new \DateTimeImmutable ('2024-01-22 23:59:59 ' )
1106
+ );
1107
+
1108
+ $ this ->assertEquals (0 , $ conflicts ->count (), "Different weeks or weekdays should not conflict " );
1109
+ }
1110
+
959
1111
protected function getExampleWithTypeOpeningHours (\DateTimeImmutable $ time )
960
1112
{
961
1113
return new $ this ->entityclass (
@@ -1239,4 +1391,40 @@ public function testValidateTypeAllowedValues()
1239
1391
$ this ->assertCount (0 , $ errors , "Type ' $ type' should be valid " );
1240
1392
}
1241
1393
}
1394
+
1395
+ public function testGetSummerizedSlotCount ()
1396
+ {
1397
+ $ availability1 = new Availability ([
1398
+ 'id ' => '1 ' ,
1399
+ 'type ' => 'appointment ' ,
1400
+ 'startTime ' => '09:00:00 ' ,
1401
+ 'endTime ' => '10:00:00 ' ,
1402
+ 'slotTimeInMinutes ' => 10 ,
1403
+ 'workstationCount ' => ['intern ' => 1 , 'public ' => 1 ],
1404
+ 'weekday ' => ['monday ' => '2 ' ],
1405
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1406
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1407
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1408
+ ]);
1409
+
1410
+ $ availability2 = new Availability ([
1411
+ 'id ' => '2 ' ,
1412
+ 'type ' => 'appointment ' ,
1413
+ 'startTime ' => '10:00:00 ' ,
1414
+ 'endTime ' => '11:00:00 ' ,
1415
+ 'slotTimeInMinutes ' => 10 ,
1416
+ 'workstationCount ' => ['intern ' => 1 , 'public ' => 1 ],
1417
+ 'weekday ' => ['monday ' => '2 ' ],
1418
+ 'startDate ' => strtotime ('2024-01-15 ' ),
1419
+ 'endDate ' => strtotime ('2024-01-15 ' ),
1420
+ 'scope ' => ['id ' => '141 ' , 'dayoff ' => []]
1421
+ ]);
1422
+
1423
+ $ list = new AvailabilityList ([$ availability1 , $ availability2 ]);
1424
+ $ slotCounts = $ list ->getSummerizedSlotCount ();
1425
+
1426
+ $ this ->assertEquals (6 , $ slotCounts ['1 ' ], "First availability should have 6 slots " );
1427
+ $ this ->assertEquals (6 , $ slotCounts ['2 ' ], "Second availability should have 6 slots " );
1428
+ }
1429
+
1242
1430
}
0 commit comments