fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
5.6k stars 169 forks source link

isoDatetime doesn't parse ISO datetime #686

Closed dearlordylord closed 1 week ago

dearlordylord commented 1 week ago

the usual format that APIs return is somewhat like 2024-06-29T22:03:56Z (e.g. https://greenwichmeantime.com/articles/clocks/iso/)

the format isoDatetime expects is 0000-01-01T00:00 - I doubt it's widely used?

a related topic is https://github.com/fabian-hiller/valibot/discussions/63#discussioncomment-6827521 - I guess it's "by design" therefore, but I'd like to leave an issue to signify that the design doesn't match usual expectations (not just mine)

reproduction:

import * as v from 'valibot';

const Schema = v.object({
  date: v.pipe(v.string(), v.isoDateTime())
});

const result = v.safeParse(Schema, {
  date: '2024-06-29T22:03:56Z'
});

console.log(result);
fabian-hiller commented 1 week ago

isoDate is for dates in the format yyyy-mm-dd. You are probably looking for isoTimestamp: https://valibot.dev/api/isoTimestamp/

dearlordylord commented 1 week ago

@fabian-hiller perfect! I overlooked this one indeed (saw "timestamp" and thought it's going to be seconds/milliseconds). Thanks 🚀