Problem using NaiveDateTime in doctest

I have written some code that parses a string and creates a NaiveDateTime. I have written some ExUnit tests that work fine, comparing the result against a naive date time constant, created using the ~N sigil.

Unfortunately, this approach does not seem to work when I put the equivalent tests into DocTests, e.g.

code: date_parse(“31-May-2021”) === ~N[2021-05-31 00:00:00]
left: %NaiveDateTime{calendar: Calendar.ISO, day: 31, hour: 0, microsecond: {0, 0}, minute: 0, month: 5, second: 0, year: 2021}
right: ~N[2021-05-31 00:00:00]

Is there some reason why the comparison why the comparison works in one context but not in another? Is is due to the use of the ‘===’ operator? If so, is there any way I can modify this behaviour?

please note, I am using the Timex library to do the actual parsing. i am adding some metadata of my own, which I have omitted from this example, for simplicity.

Closed, because of OP request.

1 Like