I did a bit of research. Many other languages use some form of operator overloading to do datetime comparison. The ones that do something different:
- Java has LocalDateTime.compareTo(other) <https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalDateTime.html#compareTo(java.time.chrono.ChronoLocalDateTime)>, returning an integer representing gt/lt/eq. There is also LocalDateTime.isBefore(other) <https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/LocalDateTime.html#isBefore(java.time.chrono.ChronoLocalDateTime)>, LocalDateTime.isAfter(other), and LocalDateTime.isEqual(other). The LocalDateTime.is{Before, After} methods are non-inclusive (<, >) comparisons. They are instance methods, so usage is like `myTime1.isBefore(myTime2)` - OCaml's "calendar" library provides a Date.compare <https://ocaml.org/p/calendar/3.0.0/doc/CalendarLib/Date/index.html#val-compare> function that returns an integer representing gt/lt/eq (for use in OCaml's List.sort function, which sorts a list according to the provided comparison function). It also provides Date.> <https://ocaml.org/p/calendar/3.0.0/doc/CalendarLib/Date/index.html#val-(%3E)>, and Date.>= <https://ocaml.org/p/calendar/3.0.0/doc/CalendarLib/Date/index.html#val-(%3E=)>, etc. Worth noting is that OCaml allows you to do expression-level module imports, like *Date.(my_t1 > my_t2)* to use Date's *>* function in the parenthesized expression without needing to *open Date* in the entire scope ("open" is OCaml's "import") - this could potentially be possible in Elixir using a macro? - Golang: t1.After(t2) <https://pkg.go.dev/time#Time.After>, t1.Before(t2), t1.Equal(t2). Non-inclusive (> and <). - Clojure clj-time library: (after? t1 t2) <https://clj-time.github.io/clj-time/doc/clj-time.core.html#var-after.3F>, (before? t1 t2) <https://clj-time.github.io/clj-time/doc/clj-time.core.html#var-before.3F>, and (equal? t1 t2) <https://clj-time.github.io/clj-time/doc/clj-time.core.html#var-equal.3F>. IMO the argument order is still confusing in these. On Sunday, October 30, 2022 at 3:15:14 AM UTC-4 José Valim wrote: > I am definitely in favor of clearer APIs. > > However, it would probably be best to explore how different libraries in > different languages tackle this. Can you please explore this? In > particular, I am curious to know if before/after mean "<" and ">" > respectively or if they mean "<=" and "=>" (I assume the former). And also > if some libraries feel compelled to expose functions such as > "after_or_equal" or if users would have to write Date.equal?(date1, date2) > or Date.earlier?(date1, date2), which would end-up doing the double of > conversions. > > -- 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/fcd07389-c6a0-497d-9c09-7f1eacf620c6n%40googlegroups.com.