Skip to content

Commit

Permalink
Fix comparing Instants that share the same day
Browse files Browse the repository at this point in the history
This commit fixes an incorrect implementation of comparing two Instants
that are on the same day. My original implementation was turned out to
be buggy. Using `ChronoUnit#between` is the way to go!
  • Loading branch information
macklinu committed May 19, 2016
1 parent 24e3e40 commit 8b6b20a
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public static Instant fromEstString(String text) {
}

public static boolean areOnSameDay(Instant left, Instant right) {
Instant leftTime = left.truncatedTo(ChronoUnit.DAYS);
Instant rightTime = right.truncatedTo(ChronoUnit.DAYS);
return leftTime.compareTo(rightTime) == 0;
return ChronoUnit.DAYS.between(left, right) == 0;
}

public static String dayTimeString(Instant instant) {
Expand Down

0 comments on commit 8b6b20a

Please sign in to comment.