@@ -759,7 +759,7 @@ function (Builder $builder) {
759
759
fn (Builder $ builder ) => $ builder ->whereYear ('created_at ' , '> ' , '2023 ' ),
760
760
];
761
761
762
- yield 'where time ' => [
762
+ yield 'where time HH:MM:SS ' => [
763
763
['find ' => [['$expr ' => [
764
764
'$eq ' => [
765
765
['$dateToString ' => ['date ' => '$created_at ' , 'format ' => '%H:%M:%S ' ]],
@@ -769,6 +769,36 @@ function (Builder $builder) {
769
769
fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , '10:11:12 ' ),
770
770
];
771
771
772
+ yield 'where time HH:MM ' => [
773
+ ['find ' => [['$expr ' => [
774
+ '$eq ' => [
775
+ ['$dateToString ' => ['date ' => '$created_at ' , 'format ' => '%H:%M ' ]],
776
+ '10:11 ' ,
777
+ ],
778
+ ]], []]],
779
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , '10:11 ' ),
780
+ ];
781
+
782
+ yield 'where time HH ' => [
783
+ ['find ' => [['$expr ' => [
784
+ '$eq ' => [
785
+ ['$dateToString ' => ['date ' => '$created_at ' , 'format ' => '%H ' ]],
786
+ '10 ' ,
787
+ ],
788
+ ]], []]],
789
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , '10 ' ),
790
+ ];
791
+
792
+ yield 'where time DateTime ' => [
793
+ ['find ' => [['$expr ' => [
794
+ '$eq ' => [
795
+ ['$dateToString ' => ['date ' => '$created_at ' , 'format ' => '%H:%M:%S ' ]],
796
+ '10:11:12 ' ,
797
+ ],
798
+ ]], []]],
799
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , new \DateTimeImmutable ('2023-08-22 10:11:12 ' )),
800
+ ];
801
+
772
802
yield 'where time > ' => [
773
803
['find ' => [['$expr ' => [
774
804
'$gt ' => [
@@ -907,6 +937,24 @@ public static function provideExceptions(): iterable
907
937
'Missing expected ending delimiter "/" in regular expression "/foo#bar" ' ,
908
938
fn (Builder $ builder ) => $ builder ->where ('name ' , 'regex ' , '/foo#bar ' ),
909
939
];
940
+
941
+ yield 'whereTime with invalid time ' => [
942
+ \InvalidArgumentException::class,
943
+ 'Invalid time format, expected HH:MM:SS, HH:MM or HH, got "10:11:12:13" ' ,
944
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , '10:11:12:13 ' ),
945
+ ];
946
+
947
+ yield 'whereTime out of range ' => [
948
+ \InvalidArgumentException::class,
949
+ 'Invalid time format, expected HH:MM:SS, HH:MM or HH, got "23:70" ' ,
950
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , '23:70 ' ),
951
+ ];
952
+
953
+ yield 'whereTime invalid type ' => [
954
+ \InvalidArgumentException::class,
955
+ 'Invalid time format, expected HH:MM:SS, HH:MM or HH, got "stdClass" ' ,
956
+ fn (Builder $ builder ) => $ builder ->whereTime ('created_at ' , new \stdClass ()),
957
+ ];
910
958
}
911
959
912
960
/** @dataProvider getEloquentMethodsNotSupported */
0 commit comments