Does anybody have any thoughts or recommendations for storing timestamps in xtdb? I've been using java.util.Date, but I just came across https://codeblog.jonskeet.uk/2017/04/23/all-about-java-util-date/
Hey @jf.slack-clojurians thanks for following up - to confirm what was going wrong previously:
1. [(= 0 (. updated-at (compareTo ts)))] - Clojure-like expression evaluation only takes place 1 level deep, meaning (. updated-at (compareTo ts)) just gets treated as a quoted list here
2. [(.equals updated-at ts)] expression evaluation is actually restricted to clojure.core and fully qualified function calls, meaning you can't use interop syntax (you could wrap it in your own function and then call that though)
yep, this seems reasonable - fwiw I usually use either java.time.Instant if it's a UTC timestamp or java.time.ZonedDateTime if the business domain cares about the time-zone
continuing, how do I compare these timestamps in xtdb? I was expecting a predicate to be able to work... but from my testing it would appear that you can't have any "more complex than simple" predicate functions. Here's a sample representative query:
(biff/q db
'{find [id updated-at]
:in [group ts]
:where [[...] [(= 0 (. updated-at (compareTo ts)))]]}
group-id ts-value)
(little note: I am for the moment still using java.util.Dates, hence the compareTo)
The given ts-value IS an expected value in the database, and does match a document (if you change the :where clause from [(= 0 (. updated-at (compareTo ts)))] to just a simple predicate [(= updated-at ts-value)] u get the expected document. But not so with the more complex one.Even using a simple predicate (but using java interop!) tells me that perhaps xtdb's clojure support with predicates is limited: with [(.equals updated-at ts)] does not work
thank God for history search! as it turns out I can compare dates using >. I was under the impression initially that > does not work; I'll say it was probably too much stuff to grok and I missed something 🙂 For my specific use case at least, > works. Booyah!