Fork me on GitHub
#clojure-spec
<
2018-11-12
>
asilverman19:11:28

#clojure-spec - hi all, could you help me understand why

(inst? (t/date-time 1986 10 14))
=> false

schmee19:11:20

I guess t/ is clj-time/?

ghadi19:11:34

@ariel.silverman (class (t/date-time 1986 10 14)) would be some third-party Joda time thing, which isn't in scope of the inst? predicate

asilverman19:11:46

@ferossgp @schmee - fair enough. How do I sample a joda time thing then?

asilverman19:11:26

#clojure-spec - I was hoping to ask for some help generating samples for clj-time/date-time since I am currently interested in testing my spec and using the spec as a generator for unit tests. Can anyone spare a couple minutes to help or point me out to some resource that can assist me in this goal?

schmee20:11:23

something like this should get you going:

(ns foo
  (:require [clojure.spec :as s]
            [clojure.spec.gen :as gen]
            [clojure.test.check.generators :as tg]))
            [clj-time.coerce :as c]

(def epoch-2000-01-01 946684800)

(def epoch-2100-01-01 4102444800)

(def date-range
  (tg/large-integer* {:min epoch-2000-01-01 :max epoch-2100-01-01}))

(s/def ::timestamp
  (s/spec nat-int?
          :gen #(tg/fmap #(c/from-long %) (tg/large-integer* {:min epoch-2000-01-01 :max epoch-2100-01-01})))

asilverman20:11:26

@schmee Thank you! Actually I was looking into leveraging the specs specified here as part of my spec definition: https://github.com/clj-time/clj-time/blob/master/src/clj_time/spec.clj

asilverman20:11:29

I was able to require the namespace clj-time.spec and now I am trying to figure out how to do the dynamic binding of *period*

schmee19:11:46

@ariel.silverman I have a one around for that, sec…