In this case, because Elixir is passing the `<` and `>` comparisons to the underlying BEAM operations and there’s no overloading to say that `left < right` should mean `DateTime.compare(left, right) < 0` and `left > right` should mean `DateTime.compare(left, right) > 0` (if I’m remembering `DateTime.compare/2` correctly).
`CompareChain` does that, but it’s something that gets opted into. -a On Thu, Mar 2, 2023 at 10:42 PM 최병욱 <cbw0...@gmail.com> wrote: > So Why don't we implicitly sort it so that it can be compared by > inequality sign(> or <)? > > 2023년 3월 3일 금요일 오전 10시 3분 25초 UTC+9에 william.l...@cargosense.com님이 작성: > >> Shameless plug: I wrote a library called `CompareChain` that allows you >> to use operators like `<` and `>` on structs like `DateTime`. >> >> Hexdocs: https://hexdocs.pm/compare_chain/readme.html >> >> On Thursday, March 2, 2023 at 10:54:08 AM UTC-5 Jay Rogov wrote: >> >>> Because the underlying structure used to represent DateTime is a struct, >>> which is simply a map under the hood. >>> Erlang/Elixir uses a rather arbitrary order of keys (e.g. hour -> year >>> -> day -> minute) when comparing 2 maps which you can't control. >>> >>> Thus, you need to have a specific function that would compare these >>> structs according to implied field order (year -> month -> day -> hour -> >>> etc.) >>> >>> More: >>> https://hexdocs.pm/elixir/main/NaiveDateTime.html#module-comparing-naive-date-times >>> >>> On Thursday, 2 March 2023 at 4:38:00 pm UTC+1 cbw...@gmail.com wrote: >>> >>>> Can't you compare DateTime with '>' or '<' instead of DateTime.compare? >>>> >>> -- > You received this message because you are subscribed to the Google Groups > "elixir-lang-core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elixir-lang-core+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elixir-lang-core/afa3830a-8944-4e12-84cc-d8e28d9fceb0n%40googlegroups.com > <https://groups.google.com/d/msgid/elixir-lang-core/afa3830a-8944-4e12-84cc-d8e28d9fceb0n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Austin Ziegler • halosta...@gmail.com • aus...@halostatue.ca http://www.halostatue.ca/ • http://twitter.com/halostatue -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAJ4ekQuHMtqrAVs-kwCo4NQC7vyWV3O8RpAm3c6tgDoiVa%2B5bw%40mail.gmail.com.