@@ -361,13 +361,21 @@ export class ZodSchemaFactory<
361361 ZodUtils . addDecimalValidation ( z . string ( ) , attributes , this . extraValidationsEnabled ) ,
362362 ] ) ;
363363 } )
364- . with ( 'DateTime' , ( ) => this . makeDateTimeValueSchema ( ) )
364+ . with ( 'DateTime' , ( ) =>
365+ this . hasAttribute ( attributes , '@db.Date' )
366+ ? z . union ( [ z . iso . date ( ) , this . makeDateTimeValueSchema ( ) ] )
367+ : this . makeDateTimeValueSchema ( ) ,
368+ )
365369 . with ( 'Bytes' , ( ) => z . instanceof ( Uint8Array ) )
366370 . with ( 'Json' , ( ) => this . makeJsonValueSchema ( ) )
367371 . otherwise ( ( ) => z . unknown ( ) ) ;
368372 }
369373 }
370374
375+ private hasAttribute ( attributes : readonly AttributeApplication [ ] | undefined , name : string ) {
376+ return attributes ?. some ( ( attribute ) => attribute . name === name ) ?? false ;
377+ }
378+
371379 @cache ( )
372380 private makeEnumSchema ( _enum : string ) {
373381 const enumDef = getEnum ( this . schema , _enum ) ;
@@ -505,6 +513,7 @@ export class ZodSchemaFactory<
505513 ! ! fieldDef . optional ,
506514 withAggregations ,
507515 allowedFilterKinds ,
516+ fieldDef . type === 'DateTime' ? fieldDef . attributes : undefined ,
508517 ) ;
509518 }
510519 }
@@ -792,14 +801,15 @@ export class ZodSchemaFactory<
792801 optional : boolean ,
793802 withAggregations : boolean ,
794803 allowedFilterKinds : string [ ] | undefined ,
804+ attributes ?: readonly AttributeApplication [ ] ,
795805 ) {
796806 return match ( type )
797807 . with ( 'String' , ( ) => this . makeStringFilterSchema ( optional , withAggregations , allowedFilterKinds ) )
798808 . with ( P . union ( 'Int' , 'Float' , 'Decimal' , 'BigInt' ) , ( type ) =>
799809 this . makeNumberFilterSchema ( type , optional , withAggregations , allowedFilterKinds ) ,
800810 )
801811 . with ( 'Boolean' , ( ) => this . makeBooleanFilterSchema ( optional , withAggregations , allowedFilterKinds ) )
802- . with ( 'DateTime' , ( ) => this . makeDateTimeFilterSchema ( optional , withAggregations , allowedFilterKinds ) )
812+ . with ( 'DateTime' , ( ) => this . makeDateTimeFilterSchema ( optional , withAggregations , allowedFilterKinds , attributes ) )
803813 . with ( 'Bytes' , ( ) => this . makeBytesFilterSchema ( optional , withAggregations , allowedFilterKinds ) )
804814 . with ( 'Json' , ( ) => this . makeJsonFilterSchema ( optional , allowedFilterKinds ) )
805815 . with ( 'Unsupported' , ( ) => z . never ( ) )
@@ -859,13 +869,17 @@ export class ZodSchemaFactory<
859869 return schema ;
860870 }
861871
862- @cache ( )
863872 private makeDateTimeFilterSchema (
864873 optional : boolean ,
865874 withAggregations : boolean ,
866875 allowedFilterKinds : string [ ] | undefined ,
876+ attributes ?: readonly AttributeApplication [ ] ,
867877 ) : ZodType {
868- const filterValueSchema = z . union ( [ z . iso . date ( ) , this . makeDateTimeValueSchema ( ) ] ) ;
878+ // For DateTime fields with @db .Date, allow plain date strings in filters
879+ const filterValueSchema = attributes && this . hasAttribute ( attributes , '@db.Date' )
880+ ? z . union ( [ z . iso . date ( ) , this . makeDateTimeValueSchema ( ) ] )
881+ : this . makeDateTimeValueSchema ( ) ;
882+
869883 const schema = this . makeCommonPrimitiveFilterSchema (
870884 filterValueSchema ,
871885 optional ,
0 commit comments