Hi everyone,
I’ve started a process of migrating our system from using clj-time to java-time. I’ve been doing it in small stages since introducing postgres into the system. All the recent namespaces and data has been handled by java-time with great success. I’d like to standardize on java-time in the long run.
At a higher level I’ve also started formalizing what these date values mean to our domain, and this has been a very fruitful exercise. Now that I’ve hit parts of the system where java.time
, inst
's and joda.*
values start flowing the through the same functions it has gotten interesting. I’ve so far managed to use a protocol with “domain specific functions” and extending the various types to do the required dances and it has worked out quite well.
We’re very lucky in our domain that so far we’ve only cared about “local dates”, so working with postgres date
columns and Datomic :db.type/instant
attributes has been smooth sailing.
My question is about getting java.time.LocalDate
values in and out of Datomic, and making sure I don’t accidently shift a day? I understand Datomic only uses instants (java.util.Date
) values under the hood.
Reading existing values I know I can pass them to java-time/local-date
providing UTC as the timezone and I’ll get the date I want. I accept this because everything I’ve read about java.util.Date
and instants told me the underlying value is a UTC value, regardless of what toString()
produces in the repl.
For casting to an instant I’ve found an example using the java.util.Date.from()
, passing in the java.time.LocalDate
object, and I still need to play with that a bit more to ensure it does what it says on the tin.
Is there something obvious I’m missing in this context?
I’m well aware of the obvious insanity of switching date/time handling approaches I also know we’re very fortunate that we don’t need to deal with time, or time zones, only local dates, and this significantly de-risks the entire endeavor.
Even if you have experiences to share about the differences between the two libraries, and the gotchas in their respective ways of thinking about dates, we could build up some knowledge here for others to find in the future.