Skip to content
Browse files
fix: fieldvalue gettimestamp (#279)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue]( before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes #16
  • Loading branch information
Praful Makani committed Apr 16, 2020
1 parent f7e89ab commit 4478a230a130cab45735e198a204fc9163b5a00e
@@ -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();

@@ -89,6 +89,14 @@ public void testFromPb() {
assertEquals(FieldValue.fromPb(TIMESTAMP_FIELD), value.getRepeatedValue().get(1));

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

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

0 comments on commit 4478a23

Please sign in to comment.