Skip to content
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

fix: fieldvalue gettimestamp #279

Merged
merged 1 commit into from Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -182,7 +182,9 @@ public boolean getBooleanValue() {
public long getTimestampValue() {
// timestamps are encoded in the format 1408452095.22 where the integer part is seconds since
// epoch (e.g. 1408452095.22 == 2014-08-19 07:41:35.220 -05:00)
return new Double(Double.valueOf(getStringValue()) * MICROSECONDS).longValue();
BigDecimal secondsWithMicro = new BigDecimal(getStringValue());
BigDecimal scaled = secondsWithMicro.scaleByPowerOfTen(6);
return scaled.longValue();
}

/**
Expand Down
Expand Up @@ -89,6 +89,14 @@ public void testFromPb() {
assertEquals(FieldValue.fromPb(TIMESTAMP_FIELD), value.getRepeatedValue().get(1));
}

@Test
public void testTimestamp() {
FieldValue fieldValue = FieldValue.of(FieldValue.Attribute.PRIMITIVE, "-1.9954383398377106E10");
long received = fieldValue.getTimestampValue();
long expected = -19954383398377106L;
assertEquals(expected, received);
}

@Test
public void testEquals() {
FieldValue booleanValue = FieldValue.of(FieldValue.Attribute.PRIMITIVE, "false");
Expand Down