ajv-formats icon indicating copy to clipboard operation
ajv-formats copied to clipboard

date-time accept timestamp without time zone

Open kaneda-san opened this issue 2 years ago • 2 comments

According to ajv-formats documentation, "date-time" format specify that time-zone is mandatory. Unfortunately since full validation mode format has been added, it seems that time-zone is not mandatory anymore:

import ajvFormats from "ajv-formats"

const dateWithoutTimeZone = '2022-07-06T13:12:43';
const dateWithTimeZone = '2022-07-06T13:12:43Z';

// validation with new full format mode does not work as expected
console.log(ajvFormats.get("date-time").validate(dateWithoutTimeZone)) // true => should return false
console.log(ajvFormats.get("date-time").validate(dateWithTimeZone)) // true => ok

// validation with fast format mode is ok
console.log(new RegExp(ajvFormats.get("date-time", "fast").validate).test(dateWithoutTimeZone)) // false => ok
console.log(new RegExp(ajvFormats.get("date-time", "fast").validate).test(dateWithTimeZone)) // true => ok

kaneda-san avatar Jul 06 '22 14:07 kaneda-san

If you confirm the issue, I could propose a pull request.

kaneda-san avatar Jul 06 '22 14:07 kaneda-san

Same issue for me, but it's fixed in v3.0.0-rc.0

thobson avatar Sep 24 '22 09:09 thobson