hapijs / joi-date

Joi extensions for dates
Other
83 stars 25 forks source link

Add support for UTC parsing mode #9

Closed Wenzil closed 6 years ago

Wenzil commented 6 years ago

When coercing a date string omitting the time part (e.g. YYYY-MM-DD), it was previously always parsed in local time. For example in the EST time zone, 2018-01-01 parsed to 2018-01-01:05:00:00.000Z.

This PR adds an optional utc mode to Joi.date() coercion. Usage:

const schema = Joi.date()
  .utc()
  .format('YYYY-MM-DD');
schema.validate('2018-01-01');

This parses to 2018-01-01:00:00:00.000Z regardless of local time zone

lock[bot] commented 4 years ago

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.