-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable to pass "now" in date.min and date.max #449
Conversation
It is not currently possible to validate a date relatively to the current time. For example, the following schema will always validate relatively to the time of the `schema` object allocation: ```javascript var schema = { date: Joi.date().min(new Date()) }; ``` This patch addresses this issue by adding a new `'now'` placeholder. It dynamically computes the current time on-the-fly at each comparison. Allowing to always compare relatively to the current time. ```javascript var schema = { // Ensure the date field cannot represent a past date date: Joi.date().min('now') }; ```
hmm... how about adding "a hour ago" as well? I mean, it should really be a function imho. |
I agree it could be a function. I wanted to keep it simple. The thing is I remember an issue where Eran didn't wanted to accept custom functions (cannot find it). Do you know any JS library to transform relative date ( |
I've merged this as is for the time being but I agree with @rlidwka, we need to come up with a better solution. Just to lay the state of things from what I gathered, Joi needs to be able to :
I'm thinking about ways to achieve this but if you already have an idea feel free to open an issue @rlidwka :) |
I already have an idea. There is no other way, really. |
That answers to only one of those 3 conditions. |
It answers to all three. Custom function can validate stuff, and it can be serialized. Documentation might require another custom function to generate it, but there is nothing unsolvable there. |
Never said it was, just saying it's more tricky than "just support functions and be done with it". |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
It is not currently possible to validate a date relatively to the
current time. For example, the following schema will always validate
relatively to the time of the
schema
object allocation:This patch addresses this issue by adding a new
'now'
placeholder.It dynamically computes the current time on-the-fly at each comparison.
Allowing to always compare relatively to the current time.