Skip to content

Make the zoned types' compareTo match the JDK's - #21

Merged
yogthos merged 1 commit into
mainfrom
fix/compare-to-jdk-order
Oct 17, 2026
Merged

yogthos merged 1 commit into
mainfrom
fix/compare-to-jdk-order

Conversation

@yogthos

@yogthos yogthos commented Oct 17, 2026

Copy link
Copy Markdown
Member

ZoneOffset sorted ascending where the JDK orders by descending total seconds,
so a sort of offsets came out reversed. ZonedDateTime and OffsetDateTime
compared by the instant's sign only; they now follow the JDK: epoch second, nano
difference, local date-time, and for ZonedDateTime the zone id. Every compareTo
also casts its argument, so another type is a ClassCastException instead of an
NPE or an answer of 1.

ZoneOffset sorted ascending where the JDK orders by descending total seconds,
so a sort of offsets came out reversed. ZonedDateTime and OffsetDateTime
compared by the instant's sign only; they now follow the JDK: epoch second, nano
difference, local date-time, and for ZonedDateTime the zone id. Every compareTo
also casts its argument, so another type is a ClassCastException instead of an
NPE or an answer of 1.
@yogthos
yogthos merged commit cb2e1c7 into main Oct 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant