You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
used with (e.g. hapi application, another framework, standalone, ...): standalone
any other relevant information:
What problem are you trying to solve?
I wish to validate and convert a numerical value into a proper Date object. The raw value is a number of the format YYYYMMDD. The data is received from an API which I don't control.
Additionally, I want to be able to specify the correct expected output type in my schema, i.e. using Joi.date(). I am using joi-to-typescript to generate the Typescript interface for this value (which I want to be a Date, not a number or anything else).
The problem is the number is cast into a UNIX/millisecond epoch timestamp and the format option is ignored.
Joi.date().validate(20211029)// {value: Thu Jan 01 1970 06:36:51 GMT+0100 (Greenwich Mean Time)}Joi.date().format("YYYYMMDD").validate(20211029)// {value: Thu Jan 01 1970 06:36:51 GMT+0100 (Greenwich Mean Time)}
Ideally, if I could coerce the value into a Joi.string() first and then into Joi.date() that would solve my problem.
Do you have a new or modified API suggestion to solve the problem?
It would be great if an option was added to provide more control over how the raw value is coerced. It should allow a numeric value to be cast into a string before parsing as a Date rather than treating all numbers as epoch timestamps.
Thanks!
The text was updated successfully, but these errors were encountered:
Context
What problem are you trying to solve?
I wish to validate and convert a numerical value into a proper Date object. The raw value is a number of the format YYYYMMDD. The data is received from an API which I don't control.
Additionally, I want to be able to specify the correct expected output type in my schema, i.e. using
Joi.date()
. I am using joi-to-typescript to generate the Typescript interface for this value (which I want to be aDate
, not a number or anything else).The problem is the number is cast into a UNIX/millisecond epoch timestamp and the
format
option is ignored.Ideally, if I could coerce the value into a
Joi.string()
first and then intoJoi.date()
that would solve my problem.I have found a workaround using
custom
:Do you have a new or modified API suggestion to solve the problem?
It would be great if an option was added to provide more control over how the raw value is coerced. It should allow a numeric value to be cast into a string before parsing as a Date rather than treating all numbers as epoch timestamps.
Thanks!
The text was updated successfully, but these errors were encountered: