Why doesn't `Calendar.ISO.naive_datetime_from_iso_days/1` return a `NaiveDateTime` struct?

Why doesn’t Calendar.ISO.naive_datetime_from_iso_days/1 return a NaiveDateTime struct? Instead it returns a tuple containing the year, month, etc.

https://hexdocs.pm/elixir/Calendar.ISO.html#naive_datetime_from_iso_days/1

I believe that any calendar function that is itself consumed in calendar implementations returns a tuple, not the struct. Since naive_datetime_from_iso_days/1 is called in Date, DateTime, and Date.Range is returns a tuple. I think this also reduces the chance of recursive compilation errors due to when a struct is available…

1 Like

I think that are primarily internal functions that not used in typically handling Dates, Times, or Calendar functions. Therefore the names don’t refer to NaiveDateTime but mean a naive date time.

I also asked the question on IRC and jose replied:

josevalim> it returns tuples because it is meant to be used by NaiveDateTime to build its own stuff
josevalim> if it returned NaiveDateTime, we would have cyclic dependencies, which i try to avoid

2 Likes