Skip to content

Commit

Permalink
Fix pack stream V2 test
Browse files Browse the repository at this point in the history
To not expect DateTime be converted to epoch second in UTC. It is
instead converted to epoch second in local time.
  • Loading branch information
lutovich committed Apr 3, 2018
1 parent b9c36ad commit bee069a
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ public void shouldWriteZonedDateTimeWithOffset() throws Exception
int index = buf.readableBytes() - Integer.BYTES - Byte.BYTES - Short.BYTES - Byte.BYTES - Integer.BYTES - Byte.BYTES;
ByteBuf tailSlice = buf.slice( index, buf.readableBytes() - index );

assertByteBufContains( tailSlice, INT_32, (int) dateTime.toEpochSecond(), INT_16, (short) dateTime.getNano(), INT_32, zoneOffset.getTotalSeconds() );
assertByteBufContains( tailSlice,
INT_32, (int) localEpochSecondOf( dateTime ),
INT_16, (short) dateTime.getNano(),
INT_32, zoneOffset.getTotalSeconds() );
}

@Test
Expand All @@ -292,7 +295,7 @@ public void shouldReadZonedDateTimeWithOffset() throws Exception
Object unpacked = packAndUnpackValue( packer ->
{
packer.packStructHeader( 3, (byte) 'F' );
packer.pack( dateTime.toInstant().getEpochSecond() );
packer.pack( localEpochSecondOf( dateTime ) );
packer.pack( dateTime.toInstant().getNano() );
packer.pack( zoneOffset.getTotalSeconds() );
} );
Expand All @@ -316,7 +319,7 @@ public void shouldWriteZonedDateTimeWithZoneId() throws Exception
ByteBuf tailSlice = buf.slice( index, buf.readableBytes() - index );

List<Number> expectedBuf = new ArrayList<>( asList(
INT_32, (int) dateTime.toInstant().getEpochSecond(),
INT_32, (int) localEpochSecondOf( dateTime ),
INT_16, (short) dateTime.toInstant().getNano(),
STRING_8, (byte) zoneNameBytes.length ) );

Expand All @@ -337,7 +340,7 @@ public void shouldReadZonedDateTimeWithZoneId() throws Exception
Object unpacked = packAndUnpackValue( packer ->
{
packer.packStructHeader( 3, (byte) 'f' );
packer.pack( dateTime.toInstant().getEpochSecond() );
packer.pack( localEpochSecondOf( dateTime ) );
packer.pack( dateTime.toInstant().getNano() );
packer.pack( zoneName );
} );
Expand Down Expand Up @@ -425,4 +428,9 @@ private MessageFormat.Writer newWriter( ByteBuf buf )
{
return messageFormat.newWriter( new ByteBufOutput( buf ), true );
}

private static long localEpochSecondOf( ZonedDateTime dateTime )
{
return dateTime.toLocalDateTime().toEpochSecond( UTC );
}
}

0 comments on commit bee069a

Please sign in to comment.