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