@ApiPropertyDate
Formats, validates, and serializes date/time fields. Supports ISO date-time strings, date-only values, time-only values, and semantic identifiers (CREATED_AT, UPDATED_AT, etc.) used by auto DTOs.
Signature
@ApiPropertyDate(properties: TApiPropertyDateProperties)Key options
| Option | Description |
|---|---|
identifier | EApiPropertyDateIdentifier describing semantic meaning (createdAt, updatedAt, expiresIn, date filters, etc.). Drives default description text. |
format | EApiPropertyDateType.DATE, DATE_TIME, or TIME. Controls regex pattern, example value, and expected serializer format. |
isArray, minItems, maxItems, isUniqueItems | Enables arrays of date values with full validation. |
isRequired, isNullable, isResponse, isExpose | Same semantics as other property decorators. |
Behavior
- Emits
@ApiPropertywith the correct ISO example, pattern, and min/max lengths. - Adds
IsDate,IsArray,ArrayMinSize,ArrayMaxSize, andArrayNotEmptyvalidators for request DTOs. - Leverages
Transformto convert ISO strings intoDateinstances (both single values and arrays). - Adds
ApiResponsePropertyand exposure decorators on response DTOs.
Example
class AuditDto {
@ApiPropertyDate({
entity: () => UserEntity,
identifier: EApiPropertyDateIdentifier.CREATED_AT,
format: EApiPropertyDateType.DATE_TIME,
isResponse: true,
})
createdAt!: Date;
@ApiPropertyDate({
entity: () => UserEntity,
identifier: EApiPropertyDateIdentifier.UPDATED_AT_FROM,
format: EApiPropertyDateType.DATE,
isRequired: false,
})
updatedAtFrom?: Date;
}Related resources
Last updated on