Skip to content

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

@cah-ricksuggs

Description

@cah-ricksuggs

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 ?

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions