Skip to content

Commit

Permalink
Fix equals for zoned date time and added MIN/MAX
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink authored and Lojjs committed Mar 16, 2018
1 parent 2f551c4 commit 63420c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Expand Up @@ -62,6 +62,9 @@

public final class DateTimeValue extends TemporalValue<ZonedDateTime,DateTimeValue>
{
public static final DateTimeValue MIN_VALUE = new DateTimeValue( ZonedDateTime.of( LocalDateTime.MIN, UTC ) );
public static final DateTimeValue MAX_VALUE = new DateTimeValue( ZonedDateTime.of( LocalDateTime.MAX, UTC ) );

public static DateTimeValue datetime( DateValue date, LocalTimeValue time, ZoneId zone )
{
return new DateTimeValue( ZonedDateTime.of( date.temporal(), time.temporal(), zone ) );
Expand Down Expand Up @@ -407,7 +410,7 @@ public boolean equals( Value other )
if ( other instanceof DateTimeValue )
{
DateTimeValue that = (DateTimeValue) other;
return value.toInstant().equals( that.value.toInstant() );
return value.equals( that.value );
}
return false;
}
Expand Down
Expand Up @@ -727,6 +727,7 @@ public static Value minValue( ValueGroup valueGroup, Value value )
case NUMBER: return MIN_NUMBER;
case GEOMETRY: return minPointValue( (PointValue)value );
case DATE: return DateValue.MIN_VALUE;
case ZONED_DATE_TIME: return DateTimeValue.MIN_VALUE;
default: throw new IllegalStateException(
format( "The minValue for valueGroup %s is not defined yet", valueGroup ) );
}
Expand All @@ -740,6 +741,7 @@ public static Value maxValue( ValueGroup valueGroup, Value value )
case NUMBER: return MAX_NUMBER;
case GEOMETRY: return maxPointValue( (PointValue)value );
case DATE: return DateValue.MAX_VALUE;
case ZONED_DATE_TIME: return DateTimeValue.MAX_VALUE;
default: throw new IllegalStateException(
format( "The maxValue for valueGroup %s is not defined yet", valueGroup ) );
}
Expand Down
Expand Up @@ -451,18 +451,18 @@ public void shouldSubtractDurationFromDateTimes()
@Test
public void shouldEqualItself()
{
assertEqual( datetime( 2018, 1, 31, 10, 52, 5, 6, UTC ), datetime( 2018, 1, 31, 10, 52, 5, 6, UTC ) );
assertEqual( datetime( 10000, 100, UTC ), datetime( 10000, 100, UTC ) );
}

@Test
public void shouldNotEqualSameTimeButDifferentTimezone()
public void shouldNotEqualSameInstantButDifferentTimezone()
{
assertNotEqual( datetime( 2018, 1, 31, 10, 52, 5, 6, UTC ), datetime( 2018, 1, 31, 10, 52, 5, 6, "+01:00" ) );
assertNotEqual( datetime( 10000, 100, UTC ), datetime( 10000, 100, ZoneOffset.of( "+01:00" ) ) );
}

@Test
public void shouldEqualSamePointInTimeInDifferentTimezone()
public void shouldNotEqualSameInstantInSameLocalTimeButDifferentTimezone()
{
assertEqual( datetime( 2018, 1, 31, 10, 52, 5, 6, UTC ), datetime( 2018, 1, 31, 11, 52, 5, 6, "+01:00" ) );
assertNotEqual( datetime( 2018, 1, 31, 10, 52, 5, 6, UTC ), datetime( 2018, 1, 31, 11, 52, 5, 6, "+01:00" ) );
}
}

0 comments on commit 63420c1

Please sign in to comment.