title: Date parameters validation using Joi
body: <p>I would validate a timestamp passed through query string. This is the routing code:</p>
  
  <p><strong>routing:</strong></p>
  
  <pre><code>router.route('/:userId/:orchardId/:sTime/:eTime')
    .get(authorize(LOGGED_USER), validate(getByInterval), controller.getByInterval);
  </code></pre>
  
  <p>I would validate the eTime parameter to have max value the actual timestamp </p>
  
  <p><strong>validation schema:</strong></p>
  
  <pre><code>getByInterval: {
      params: {
        userId: Joi.string().regex(/^[0-9]+$/, 'numbers').required(),
        orchardId: Joi.string().regex(/^[0-9]+$/, 'numbers').required(),
        sTime: Joi.date().timestamp().required(),
        eTime: Joi.date().timestamp('unix').max(moment().unix() * 1000),
      }
  </code></pre>
  
  <p><strong>test:</strong></p>
  
  <pre><code>it('should get 200 when data are found', async () =&gt; {
        const userId = 1;
        const orchardId = 1;
        const sTime = (moment().unix() * 1000) - 3000;
        const eTime = moment().unix() * 1000;
        return request(app)
          .get(`/v1/data/${userId}/${orchardId}/${sTime}/${eTime}`)
          .set('Authorization', `Bearer ${userAccessToken}`)
          .expect(httpStatus.OK)
      });
  </code></pre>
  
  <p>I tried in many ways but no one works... I receive this error:</p>
  
  <p><strong>error:</strong></p>
  
  <pre><code>{"code":400,"message":"Validation error","errors":[{"field":"eTime","location":"params","messages":["\"eTime\" must be less than or equal to \"Thu Oct 12 2017 09:49:00 GMT+0200 (CEST)\""],"types":["date.max"]}]}
  </code></pre>