KLaus_K

KLaus_K

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.

First Post!

kokolegorille

kokolegorille

Most Liked

kokolegorille

kokolegorille

Closed, because of OP request.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44778 311
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement