Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why LocalDate doesn't implements Comparable<LocalDate>?

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>?

like image 413
mkUltra Avatar asked Dec 14 '22 13:12

mkUltra


1 Answers

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.

like image 79
deHaar Avatar answered Dec 25 '22 13:12

deHaar