Skip to content

Commit

Permalink
Fix DateTimeInterval equality
Browse files Browse the repository at this point in the history
  • Loading branch information
erikc5000 committed Dec 6, 2019
1 parent d7563cf commit ff3e0f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class DateTimeInterval(
return start >= endExclusive
}

override fun equals(other: Any?): Boolean {
return other is DateTimeInterval && (isEmpty() && other.isEmpty() ||
start == other.start && endExclusive == other.endExclusive)
}

/**
* Convert this interval to a string in ISO-8601 extended format.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ class DateTimeIntervalTest : AbstractIslandTimeTest() {
assertFalse { DateTimeInterval.UNBOUNDED.hasBoundedEnd() }
}

@Test
fun `equality works correctly`() {
assertEquals(DateTimeInterval.EMPTY, DateTimeInterval.EMPTY)
assertNotEquals(DateTimeInterval.UNBOUNDED, DateTimeInterval.EMPTY)
assertNotEquals(DateTimeInterval.EMPTY, DateTimeInterval.UNBOUNDED)

val date1 = DateTime(2017, 1, 3, 30, 0, 0)
val date2 = DateTime(2017, 2, 3, 30, 0, 0)
val date3 = DateTime(2017, 3, 3, 30, 0, 0)

assertEquals(DateTimeInterval.EMPTY, date2..date1)
assertNotEquals(date1..date2, date1..date3)
assertNotEquals(date1..date3, date1..date2)
assertNotEquals(date2..date3, date1..date3)
assertNotEquals(date1..date3, date2..date3)
}

@Test
fun `inclusive end creation handles unbounded correctly`() {
val start = Date(2019, Month.MARCH, 10) at Time.MIDNIGHT
Expand Down

0 comments on commit ff3e0f8

Please sign in to comment.