Fastify AJV date-time schema validation missing timezone normalization
0 reputation · 01 Apr 2024, 21:21 UTC
Fastify request schema date-time validation and timezone conversion
A design goal is to accept ISO 8601 date-time strings in request bodies and ensure they are handled in a canonical timezone, such as UTC or a configured regional zone, before business logic runs.
Fastify uses AJV for schema validation. The format: 'date-time' keyword validates the string shape but does not transform the value. Validated data remains a raw string in request.body. There is no built-in hook or plugin that automatically converts validated date-time fields to Date objects or to a normalized offset during the request lifecycle.
The missing constraint is where and how the conversion boundary should be defined so all routes share consistent timezone handling without per-route manual parsing. The uncertainty is whether normalization belongs in schema configuration, a global request lifecycle extension, or application-level code.
Which Fastify extension point is appropriate for normalizing validated date-time strings to a canonical timezone? Should the permission boundary for conversion be enforced via schema, a global preHandler, or a custom AJV format? What is the recommended way to declare a regional timezone default for all validated date-time fields?