Skip to content
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

ensure date does not occur in the past #407

Closed
ArnoldZokas opened this issue Aug 26, 2014 · 8 comments
Closed

ensure date does not occur in the past #407

ArnoldZokas opened this issue Aug 26, 2014 · 8 comments
Assignees
Labels
feature New functionality or improvement
Milestone

Comments

@ArnoldZokas
Copy link

I want to validate input date to ensure it does not occur in the past.

Something like this...

var schema = Joi.date().min(function() { return moment().utc().toDate(); });

Is there already a way to achieve this?

@arb
Copy link
Contributor

arb commented Aug 26, 2014

This is currently not supported but there are a few issues open related to this

@ArnoldZokas
Copy link
Author

Would you accept a pull request for this?

@arb
Copy link
Contributor

arb commented Aug 27, 2014

Absolutely.

@hueniverse
Copy link
Contributor

Sorry but no functions as inputs. I'll accept a PR that handles the string 'now' as a special case for min() and max().

@a00andos
Copy link

I just wrap the schema in a function for handling this:

var startWithValid = function(value) {
  assert(_.isDate(value), 'must be a valid Date');
  return Joi.object().keys({
    start: Joi.date().min(value).required()
  });
},

And then I use it like:

 Joi.validate(input, startWithValid(new Date()),  function (err, input) { ...

@ArnoldZokas
Copy link
Author

@a00andos I am not using Joi API directly, but rather via Hapijs framework. Values passed in to min/max functions get cached.

@Marsup
Copy link
Collaborator

Marsup commented Jan 1, 2015

I think this one's been fixed in 4.8.0, closing.

@Marsup Marsup closed this as completed Jan 1, 2015
@Marsup Marsup self-assigned this Jan 1, 2015
@Marsup Marsup added this to the 4.8.0 milestone Jan 1, 2015
@hueniverse hueniverse added feature New functionality or improvement and removed request labels Sep 19, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

5 participants