Skip to content

string isoDate should allow the string to be converted to same format as date iso schema #1196

@bdgamble

Description

@bdgamble

Context

  • node version: all
  • joi version: 10.5.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

Due to a limitation with using joi as the schema for DynamoDb via https://github.com/ryanfitz/vogels I need to validate dates with joi.string().isoDate() and use the value returned from validation to store in DynamoDb. I need the date to be formatted in the simplified extended ISO format in the same way that joi.date().iso() would return.

const stringSchema = Joi.string().isoDate();
const dateSchema = Joi.date().iso();

const stringResults = Joi.validate('2017-01-01', stringSchema);
const dateResults = Joi.validate('2017-01-01', dateSchema);

// want these to be the same
console.log('string value: ', stringResults.result);
console.log('date value: ', dateResults.result);

Which result you had ?

The string schema just returns the provided string. i.e "2017-01-01" returns "2017-01-01"

What did you expect ?

I want it to return "2017-01-01T00:00:00.000Z", or an option to convert it as such

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changesChange that can breaking existing codebugBug or defectfeatureNew functionality or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions