I have some database functions which I'm testing (to make sure my queries etc. work) -- in them, I'm de/serialising records (via Database.Esqueleto.Experimental) and these contain values of type UTCTime (and Maybe UTCTime, etc.).
The problem is that I get these sorts of errors in my tests:
1) Vulture.Database.EventRepository.addEvents correctly sets the event properties
expected: 2023-05-06 21:52:13.441270819 UTC
but got: 2023-05-06 21:52:13.441271 UTC
This is sort of annoying, but I don't know how to either manipulate UTCTime values to change the precision, or to change the way the equality works here.
As you've noticed,
UTCTimeby itself has a pretty sparse api. Just about everything interesting involves going viaNominalDiffTime. For this case, I think you're best served by getting the difference between the two times and then making sure it's below some epsilon. For this, the relevant time function isdiffUTCTime, and the rest takes advantage of the extensive set of instances available forNominalDiffTime. Thanks to theNuminstance, we haveabsavailable. Thanks to theNumandFractionalinstances, we can use literals to createNominalDiffTimevalues. And of course there'sOrdfor comparisons...Feel free to adjust
epsas desired. And of course, you might need to adjust the structure of the whole thing to get good diagnostics out of the test framework.Remember this as the basic framework for working with
UTCTime- those values are just points in time. The really interesting stuff involves working withNominalDiffTimevalues which represent intervals betweenUTCTimevalues. Those intervals have a much richer API for manipulating them then the points have.