Skip to content

Update AbstractRowsEventDataDeserializer.java #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -417,7 +417,7 @@ protected Long asUnixTime(int year, int month, int day, int hour, int minute, in
if (year == 0 || month == 0 || day == 0) {
return invalidDateAndTimeRepresentation;
}
return UnixTime.from(year, month, day, hour, minute, second, millis);
return convertLocalTimestamp(UnixTime.from(year, month, day, hour, minute, second, millis));
}

protected int deserializeFractionalSeconds(int meta, ByteArrayInputStream inputStream) throws IOException {
@@ -428,6 +428,33 @@ protected int deserializeFractionalSeconds(int meta, ByteArrayInputStream inputS
}
return 0;
}

private long convertLocalTimestamp(long millis) {
TimeZone tz = TimeZone.getDefault();
Calendar c = Calendar.getInstance(tz);
long localMillis = millis;
int offset, time;

c.set(1970, Calendar.JANUARY, 1, 0, 0, 0);

// Add milliseconds
while (localMillis > Integer.MAX_VALUE)
{
c.add(Calendar.MILLISECOND, Integer.MAX_VALUE);
localMillis -= Integer.MAX_VALUE;
}
c.add(Calendar.MILLISECOND, (int)localMillis);

// Stupidly, the Calendar will give us the wrong result if we use getTime() directly.
// Instead, we calculate the offset and do the math ourselves.
time = c.get(Calendar.MILLISECOND);
time += c.get(Calendar.SECOND) * 1000;
time += c.get(Calendar.MINUTE) * 60 * 1000;
time += c.get(Calendar.HOUR_OF_DAY) * 60 * 60 * 1000;
offset = tz.getOffset(c.get(Calendar.ERA), c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.DAY_OF_WEEK), time);

return (millis - offset);
}

private static int bitSlice(long value, int bitOffset, int numberOfBits, int payloadSize) {
long result = value >> payloadSize - (bitOffset + numberOfBits);