Skip to content

Commit

Permalink
Fix short form timestamp offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Nov 8, 2023
1 parent ea7cad8 commit 7fce291
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/com/amazon/ion/impl/bin/IonEncoder_1_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private static int writeShortFormTimestampValue(WriteBuffer buffer, Timestamp va
throw new IllegalStateException("This is unreachable!");
}
} else {
long localOffset = value.getLocalOffset().longValue() / 15;
long localOffset = (value.getLocalOffset().longValue() / 15) + (14 * 4);
bits |= (localOffset & LEAST_SIGNIFICANT_7_BITS) << S_O_TIMESTAMP_OFFSET_BIT_OFFSET;

if (value.getPrecision() == Timestamp.Precision.MINUTE) {
Expand Down
40 changes: 20 additions & 20 deletions test/com/amazon/ion/impl/bin/IonEncoder_1_1Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,26 @@ public void testWriteTimestampValueWithUnknownOffsetShortForm(@ConvertWith(Strin
@ParameterizedTest
@CsvSource({
// OpCode MYYYYYYY DDDDDMMM mmmHHHHH ooooommm ssssssoo ffffffff ffffffff ffffffff ..ffffff
"2023-10-15T01:00-14:00, 01111000 00110101 01111101 00000001 01000000 00000010",
"2023-10-15T01:00+14:00, 01111000 00110101 01111101 00000001 11000000 00000001",
"2023-10-15T01:00-01:15, 01111000 00110101 01111101 00000001 11011000 00000011",
"2023-10-15T01:00+01:15, 01111000 00110101 01111101 00000001 00101000 00000000",
"2023-10-15T01:59+01:15, 01111000 00110101 01111101 01100001 00101111 00000000",
"2023-10-15T11:22+01:15, 01111000 00110101 01111101 11001011 00101010 00000000",
"2023-10-15T23:00+01:15, 01111000 00110101 01111101 00010111 00101000 00000000",
"2023-10-15T23:59+01:15, 01111000 00110101 01111101 01110111 00101111 00000000",
"2023-10-15T11:22:00+01:15, 01111001 00110101 01111101 11001011 00101010 00000000",
"2023-10-15T11:22:33+01:15, 01111001 00110101 01111101 11001011 00101010 10000100",
"2023-10-15T11:22:59+01:15, 01111001 00110101 01111101 11001011 00101010 11101100",
"2023-10-15T11:22:33.000+01:15, 01111010 00110101 01111101 11001011 00101010 10000100 00000000 00000000",
"2023-10-15T11:22:33.444+01:15, 01111010 00110101 01111101 11001011 00101010 10000100 10111100 00000001",
"2023-10-15T11:22:33.999+01:15, 01111010 00110101 01111101 11001011 00101010 10000100 11100111 00000011",
"2023-10-15T11:22:33.000000+01:15, 01111011 00110101 01111101 11001011 00101010 10000100 00000000 00000000 00000000",
"2023-10-15T11:22:33.444555+01:15, 01111011 00110101 01111101 11001011 00101010 10000100 10001011 11001000 00000110",
"2023-10-15T11:22:33.999999+01:15, 01111011 00110101 01111101 11001011 00101010 10000100 00111111 01000010 00001111",
"2023-10-15T11:22:33.000000000+01:15, 01111100 00110101 01111101 11001011 00101010 10000100 00000000 00000000 00000000 00000000",
"2023-10-15T11:22:33.444555666+01:15, 01111100 00110101 01111101 11001011 00101010 10000100 10010010 01100001 01111111 00011010",
"2023-10-15T11:22:33.999999999+01:15, 01111100 00110101 01111101 11001011 00101010 10000100 11111111 11001001 10011010 00111011",
"2023-10-15T01:00-14:00, 01111000 00110101 01111101 00000001 00000000 00000000",
"2023-10-15T01:00+14:00, 01111000 00110101 01111101 00000001 10000000 00000011",
"2023-10-15T01:00-01:15, 01111000 00110101 01111101 00000001 10011000 00000001",
"2023-10-15T01:00+01:15, 01111000 00110101 01111101 00000001 11101000 00000001",
"2023-10-15T01:59+01:15, 01111000 00110101 01111101 01100001 11101111 00000001",
"2023-10-15T11:22+01:15, 01111000 00110101 01111101 11001011 11101010 00000001",
"2023-10-15T23:00+01:15, 01111000 00110101 01111101 00010111 11101000 00000001",
"2023-10-15T23:59+01:15, 01111000 00110101 01111101 01110111 11101111 00000001",
"2023-10-15T11:22:00+01:15, 01111001 00110101 01111101 11001011 11101010 00000001",
"2023-10-15T11:22:33+01:15, 01111001 00110101 01111101 11001011 11101010 10000101",
"2023-10-15T11:22:59+01:15, 01111001 00110101 01111101 11001011 11101010 11101101",
"2023-10-15T11:22:33.000+01:15, 01111010 00110101 01111101 11001011 11101010 10000101 00000000 00000000",
"2023-10-15T11:22:33.444+01:15, 01111010 00110101 01111101 11001011 11101010 10000101 10111100 00000001",
"2023-10-15T11:22:33.999+01:15, 01111010 00110101 01111101 11001011 11101010 10000101 11100111 00000011",
"2023-10-15T11:22:33.000000+01:15, 01111011 00110101 01111101 11001011 11101010 10000101 00000000 00000000 00000000",
"2023-10-15T11:22:33.444555+01:15, 01111011 00110101 01111101 11001011 11101010 10000101 10001011 11001000 00000110",
"2023-10-15T11:22:33.999999+01:15, 01111011 00110101 01111101 11001011 11101010 10000101 00111111 01000010 00001111",
"2023-10-15T11:22:33.000000000+01:15, 01111100 00110101 01111101 11001011 11101010 10000101 00000000 00000000 00000000 00000000",
"2023-10-15T11:22:33.444555666+01:15, 01111100 00110101 01111101 11001011 11101010 10000101 10010010 01100001 01111111 00011010",
"2023-10-15T11:22:33.999999999+01:15, 01111100 00110101 01111101 11001011 11101010 10000101 11111111 11001001 10011010 00111011",

})
public void testWriteTimestampValueWithKnownOffsetShortForm(@ConvertWith(StringToTimestamp.class) Timestamp value, String expectedBytes) {
Expand Down

0 comments on commit 7fce291

Please sign in to comment.