I'm not sure the name is right, but I like > DateTime.is?(a, operator, b), when operator :lt | :le | :eq | :ge | :gt, > which would capture the :le and :ge options.
As a usage api, we could actually have `compare?/3` especially as the name doesn't overlap with `compare/2` which would hopefully alleviate anyones concerns about the return type changing On Mon, 31 Oct 2022, at 6:23 AM, José Valim wrote: > My thought process is that a simple to use API should be the focus, because > we already have a complete API in Date.compare/2 and friends. > > On Mon, Oct 31, 2022 at 02:16 Simon McConnell <simonmcconn...@gmail.com> > wrote: >> would we want on_or_after? and on_or_before? as well then? Or something >> like DateTime.is?(a, operator, b), when operator :lt | :le | :eq | :ge | >> :gt, which would capture the :le and :ge options. >> >> On Monday, 31 October 2022 at 7:26:42 am UTC+10 José Valim wrote: >>> Thank you! >>> >>> A PR that adds before?/after? to Time, Date, NaiveDateTime, and DateTime is >>> welcome! >>> >>> >>> On Sun, Oct 30, 2022 at 6:46 PM Cliff <notcliff...@gmail.com> wrote: >>>> 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-co...@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 >>>> >>>> <https://groups.google.com/d/msgid/elixir-lang-core/fcd07389-c6a0-497d-9c09-7f1eacf620c6n%40googlegroups.com?utm_medium=email&utm_source=footer>. >> >> >> -- >> 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/e6c55604-c3ea-464c-908c-5a6092f4d8edn%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elixir-lang-core/e6c55604-c3ea-464c-908c-5a6092f4d8edn%40googlegroups.com?utm_medium=email&utm_source=footer>. > > > -- > 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/CAGnRm4%2ByT9jA7uqGX0Cyapgfx0AjW%2BU_d4Ai-NQ6vD9UsEb2uQ%40mail.gmail.com > > <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2ByT9jA7uqGX0Cyapgfx0AjW%2BU_d4Ai-NQ6vD9UsEb2uQ%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- 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/2e821e87-6ee0-4702-b69f-e2616b61b1dd%40app.fastmail.com.