Initial Problem:
In Scala, I would like to use implicit Ordering[T]#Ops
to compare two LocalDate
.
It just to use "operators" like >
instead of isAfter
.
It should be just an import: import scala.math.Ordering.Implicits._
Inspection:
Looks like it works with LocalTime
and doesn't with LocalDate
because LocalTime
instead of LocalDate
implements Comparable<LocalTime>
.
Question:
I wondering,
Why LocalDate
implements Comparable<ChronoLocalDate>
instead of Comparable<LocalDate>
?
LocalDate
in fact implements Comparable<ChronoLocalDate>
as well as ChronoLocalDate
and by implementing those two, every instance of it is of course comparable to another LocalDate
instance.
You can have a look at the JavaDocs for LocalDate
on Oracle's website.
ChronoLocalDate
is an interface that is implemented by different types of calendars in order to make them all comparable to each other. That is because there are JapaneseDate
, ThaiBuddhistDate
, HijrahDate
and at least one more. Totally different calendars that are all comparable to each other, which is great. LocalTime
, on the other hand, is just a time representation with different time zones and just doesn't have to go this interface-way to be comparable to time representations of different locales.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With