day8 / re-com

A ClojureScript library of reusable components for Reagent
https://re-com.day8.com.au
MIT License
796 stars 147 forks source link

datepicker: loosen model validation in datepicker to DateTimeProtocol #189

Closed hipitihop closed 5 years ago

hipitihop commented 5 years ago

Rename re-com.validate/goog-date? to date-like? and test arg via cljs-time.core/date? which ensures it satisfies DateTimeProtocol instead of concrete type checks. This allows consumers to provide their own date like objects e.g. day8.time.Date which may not subclass goog.date.Date for :model, :minimum & :maximum args.

danielcompton commented 5 years ago

Your use of the function date-like? reminded me that goog.date.DateLike exists: https://github.com/google/closure-library/blob/master/closure/goog/date/datelike.js.

From https://google.github.io/closure-library/api/goog.date.Date.html

Implements most methods of the native js Date object (except the time related ones, goog.date.DateTime) and can be used interchangeably with it just as if goog.date.Date was a synonym of Date. To make this more transparent, Closure APIs should accept goog.date.DateLike instead of the real Date object.

However the re-com library makes use of cljs-time, so we do actually need a date object that satisfies the cljs-time.core/DateTimeProtocol