T
(java.time.Instant/now)
в твой кодSize: a a a
T
(java.time.Instant/now)
в твой кодAC
(sort (fn [a b]
(cond
(nil? a) -1
(nil? b) 1
:else (compare b a)))
[5 nil 1 3 0])
Как
-то элегантнее можно?ST
ST
T
[{:period {:end "2020-02-02", ...}, ...}, ...]
ST
[{:period {:end "2020-02-02", ...}, ...}, ...]
PP
(reverse (sort-by (fn [x] [(if x 0 1) x])
[#inst "2023"
nil
#inst "2021"
#inst "2020"
nil
#inst "2017"]))
ST
(reverse (sort-by (fn [x] [(if x 0 1) x])
[#inst "2023"
nil
#inst "2021"
#inst "2020"
nil
#inst "2017"]))
PP
ST
#inst "2021"
даёт java.util.Date, что не очень...ST
(sort-by (fnil identity "9999") #(compare %2 %1) ["2001" "2002" "2003" nil])
АМ
АМ
(defn valid-date? [date]
(try (let [format (java.time.format.DateTimeFormatter/ofPattern "yyyy.MM.dd")]
(java.time.LocalDate/parse date format)
true)
(catch java.time.format.DateTimeParseException e
false)))
ST
АМ
ST
(java.time.LocalDate/of 2020 02 31)
ST