Skip to content

Support ISO 8601 strings in malli.experimental.time/schemas #1238

@devurandom

Description

@devurandom

malli.experimental.time/schemas already supports java.time objects, but it would be convenient if there was a pre-defined set of ISO 8601 string schemas, so I could validate "2025-10-31T14:28:Z" without having to transform it to a java.time object first.

Currently, I can either try to transform the string to a java.time.*, and get unhelpful messages in case of validation errors (cf. #1114), or I can validate using my own hand-crafted regexp:

(ns repro
  (:require
    [malli.core :as m]
    [malli.error :as me]))

(def offset-date-time-string
  "Malli schema for ISO 8601 extended format date time"
  [:re {:error/message "should be an ISO 8601 extended format date time"}
   #"^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(\.\d\d\d)?([+-][0-2]\d:[0-5]\d|Z)$"])

(me/humanize (m/explain offset-date-time-string "2025-10-31T14:28:Z"))
;=> ["should be an ISO 8601 extended format date time"]

Adding string schemas might already be a first step towards #60, too.

See-also: #1114
See-also: #60

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Not right now

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions