This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-02
Channels
- # aws-lambda (1)
- # beginners (28)
- # boot (54)
- # cider (11)
- # clara (28)
- # cljs-dev (74)
- # cljsrn (13)
- # clojure (342)
- # clojure-austin (3)
- # clojure-dusseldorf (4)
- # clojure-france (2)
- # clojure-greece (11)
- # clojure-italy (42)
- # clojure-poland (7)
- # clojure-russia (11)
- # clojure-spec (44)
- # clojure-uk (156)
- # clojure-ukraine (4)
- # clojurescript (102)
- # cursive (17)
- # datascript (19)
- # datomic (17)
- # dirac (39)
- # emacs (22)
- # funcool (56)
- # hoplon (25)
- # jobs (3)
- # jobs-discuss (31)
- # leiningen (2)
- # luminus (4)
- # lumo (3)
- # off-topic (47)
- # om (51)
- # onyx (57)
- # re-frame (13)
- # reagent (57)
- # remote-jobs (15)
- # ring (9)
- # ring-swagger (7)
- # robots (2)
- # rum (6)
- # specter (16)
- # sql (7)
- # test-check (37)
- # untangled (7)
- # yada (5)
so is anyone else constantly doing this: (s/keys ::req-un [::key-a ::key-b])
? with all the namespaced keywords I usually don't even notice what is wrong
Is there a spec for date?
Thanks @souenzzo. What about a date that is stored as a string?
I’d like the spec to validate “03/27/2016” but not “Hello World"
There are date time parsers in the Java std lib
Either that or a regex pred
(I was just joking about string? :)
user=> (import 'java.text.SimpleDateFormat)
java.text.SimpleDateFormat
user=> (def formatter (SimpleDateFormat. "MM/dd/yyyy"))
#'user/formatter
user=> (.parse formatter "03/27/2016")
#inst “2016-03-27T05:00:00.000-00:00”
you’d want to wrap up the call to .parse to catch ParseException and return false
thx a lot
(defn valid-date? [s] (try (.parse formatter s) (catch ParseException e false)))
usually you wrap that in a ThreadLocal
good point - I haven’t used much of the new java 8 stuff
you’d want to use java.time.format.DateTimeFormatter
(import [java.time.format DateTimeFormatter DateTimeParseException] java.time.LocalDate)
(def format (DateTimeFormatter/ofPattern “MM/dd/yyyy"))
(defn valid-date? [s] (try (LocalDate/parse s format) (catch DateTimeParseException _ false)))
that should be thread-safe
please burn the prior example
@mpenet what did u mean by not thread-safe?
maybe the formatter isn't thread safe?
what does it mean for a fomatter not to be thread-safe?
since formatter is a class instance and stores intermediate parse data in instance variables
Unbelievable!
it seemed like a good idea in the 90's
No, it really didnt
hi please can you help me?? how I can make a spec case insensitive:
(s/def :vtex/channel #{"KUSHKIPAGOS"})
you could replace the spec with #(= (clojure.string/upper-case %) "KUSHKIPAGOS")
on the topic of accidental double colon on ::req-un - that’s a situtation where the parameters are plainly provided statically, so MAAAAYBE warning on unrecognized keys wouldn’t be totally objectionable - but that would require trusting ppl to not abuse whatever flag enables that check
i mentioned this before, see https://www.typescriptlang.org/docs/handbook/interfaces.html and search for “excess property checking"