Fork me on GitHub
#malli
<
2022-01-12
>
rovanion11:01:10

Any recommendation on dealing with time? I've got multiple fields that hold LocalDateTime and it's not clear to me how I should express that.

ikitommi15:01:58

you could c&p code from this https://github.com/metosin/malli/pull/545, or wait for the PR or just do something like:

(def LocalDateTime
  (m/-simple-schema
    {:type 'LocalDateTime
     :pred #(instance? LocalDateTime %)
     :type-properties {:error/message "invalid date-time"
                       :decode/string #(LocalDate/parse %)
                       :json-schema {:type "string"
                                     :format "date-time"}}))

(m/validate LocalDateTime (LocalDateTime/now)) ; => true
(didn’t run that, might not work, but like that anyways.

rovanion12:01:32

When walking a schema, what does the nil that appears as the second entry in all children represent?

(def temperaturmätning                                                                                                                                                                                        
  (malli/schema                                                                                                                                                                                               
   [:map                                                                                                                                                                                                      
    [:odlingsplats [string? {:min 1}]]                                                                                                                                                                        
    [:tidpunkt     string?]]))

(malli/walk
  temperaturmätning
  (fn [schema path children _]
    (println "Path: " path)
    (println "Type: " (malli/type schema))
    (print "Schema: ")
    (clojure.pprint/pprint schema)
    (clojure.pprint/pprint children)
    (case (malli/type schema)
      string?  [:input {:type "text"} (-> path last name)]
      :map             [:div.input-group children])
    ))

;; [:div.input-group                                                                                                                                                                                          
;;  [[:odlingsplats nil [:input {:type "text"} "odlingsplats"]]                                                                                                                                               
;;  [:tidpunkt nil [:input {:type "text"} "tidpunkt"]]]]   

ikitommi12:01:46

entry properties, e.g. in`[:map [:x {:optional true} :int]]`

rovanion13:01:03

Ah, of course!

Ben Sless16:01:37

@ikitommi since the time PR is back on the agenda, what do you think about tackling the protocols split first?

ikitommi18:01:04

Thanks for reminding. I’ve been thinking about it. Just commented on the issue.