Schema date validators?

Hi, I'm migrating my current validators from Zod to Effect Schema.
export const birthdateValidator = z
  .date({ required_error: "Fecha de nacimiento requerida" })
  .min(new Date("1900-01-01"), "Fecha de nacimiento no puede ser anterior a 1900")
  .max(new Date(), "Fecha de nacimiento no puede ser posterior a la fecha actual")

export const BirthdateValidator = pipe(
  Schema.Date.annotations({ message: () => "Fecha de nacimiento requerida" }),
  Schema.filter((x) => x.getTime() >= new Date("1900-01-01").getTime(), {
    message: () => "Fecha de nacimiento no puede ser anterior a 1900",
  }),
  Schema.filter((x) => x.getTime() <= new Date().getTime(), {
    message: () => "Fecha de nacimiento no puede ser posterior a la fecha actual",
  })
)


This is the only way I found to validate a date range, is there a cleaner way?
I mean, this works, just asking 🙂

Hi in advance, TheStockBroker
Was this page helpful?