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

joi.date().timestamp() failing validation for millisecond value #919

Closed
cah-ricksuggs opened this issue Jun 11, 2016 · 4 comments
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@cah-ricksuggs
Copy link

Context

  • node version: v4.4.5
  • joi version: 8.4.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

According to the documentation here: https://github.com/hapijs/joi/blob/v9.0.0-3/API.md#datetimestamptype; a millisecond value should pass validation for joi.date().timestamp()

However, when I try to validate with convert: true the millisecond value is converted to ISO date string. Additionally, when passing convert: false the validation fails completely.

Thanks.

var joi = require('joi');

const schema = joi.object({

  create_dt: joi.date().timestamp()

});

// converts to ISO date string???
var result1 = joi.validate({create_dt: 1465599344356}, schema);

console.log('Result 1:')
console.log(JSON.stringify(result1));
console.log('\n')

// fails validation ???
var result2 = joi.validate({create_dt: 1465599344356}, schema, {convert: false});

console.log('Result 2: ')
console.log(JSON.stringify(result2))

Which result you had ?

Result 1:
{"error":null,"value":{"create_dt":"2016-06-10T22:55:44.356Z"}}


Result 2: 
{"error":{"isJoi":true,"name":"ValidationError","details":[{"message":"\"create_dt\" must be a valid timestamp or number of milliseconds","path":"create_dt","type":"date.timestamp.javascript","context":{"key":"create_dt"}}],"_object":{"create_dt":1465599344356}},"value":{"create_dt":1465599344356}}

What did you expect ?

@Marsup
Copy link
Collaborator

Marsup commented Jun 11, 2016

#794

@Marsup Marsup closed this as completed Jun 11, 2016
@Marsup Marsup added the non issue Issue is not a problem or requires changes label Jun 11, 2016
@Marsup Marsup self-assigned this Jun 11, 2016
@Marsup
Copy link
Collaborator

Marsup commented Jun 11, 2016

If you want numbers you should check for numbers, not dates.

@cah-ricksuggs
Copy link
Author

@Marsup The error message is undeniably false.

{"error":{"isJoi":true,"name":"ValidationError","details":[{"message":"\"create_dt\" must be a valid timestamp or number of milliseconds","path":"create_dt","type":"date.timestamp.javascript","context":{"key":"create_dt"}}],"_object":{"create_dt":1465599344356}},"value":{"create_dt":1465599344356}}

Thanks for clarifying, this library has a lot of promise!

@Marsup Marsup added bug Bug or defect and removed non issue Issue is not a problem or requires changes labels Jun 12, 2016
@Marsup Marsup added this to the 8.4.2 milestone Jun 12, 2016
Marsup added a commit that referenced this issue Jun 12, 2016
@Marsup
Copy link
Collaborator

Marsup commented Jun 12, 2016

Actually you're right, this will save me the trouble of explaining again and again the same behavior :)

@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants