ajv-validator / ajv-validator/ajv-keywords

`date` and `date-time` do not support `formatMaximum` validation for years >=10000 🤷‍♂️

Abierto
#61 3 comentarios 2 reacciones 0 asignados Ver en GitHub
limitation
Lenguaje dominante
TypeScript
Estrellas
257
Forks
51
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

When you create a `Date` object in UTC timezone in JavaScript as follows

```js
new Date(10000, null)
```

and convert it to ISO string, you get `+010000-01-01T00:00:00.000Z` (notice the leading `+0` string).

This seems to [follow the ISO 8601 standard](https://en.wikipedia.org/wiki/ISO_8601#Years).

This breaks the `formatMaximum` (and possibly also `formatMinimum`) validation because the dates are compared as plain strings, ie. eventually you get to a point where your compare `"2018"` and `"+010000"` and as far as JS strings are concerned, `2018` is greater, even though the intention was to compare year 2018 and year 10000.

Here, the ISO string is split into year component:

https://github.com/epoberezkin/ajv-keywords/blob/5f9eccc2e2b95745f659ef1abf5488f70da496f2/keywords/_formatLimit.js#L83-L87

And here is the actual string comparison of the two dates:

https://github.com/epoberezkin/ajv-keywords/blob/5f9eccc2e2b95745f659ef1abf5488f70da496f2/keywords/_formatLimit.js#L62-L67

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.