public static Timestamp previous(Timestamp timestamp) {
    if (timestamp.equals(Timestamp.MIN_VALUE)) {
      return timestamp;
    }

    final int nanos = timestamp.getNanos();
    final long seconds = timestamp.getSeconds();
    if (nanos - 1 >= 0) {
      return Timestamp.ofTimeSecondsAndNanos(seconds, nanos - 1);
    } else {
      return Timestamp.ofTimeSecondsAndNanos(seconds - 1, NANOS_PER_SECOND - 1);
    }
  }
@Test
  public void testPreviousDecrementsNanosWhenPossible() {
    assertEquals(
        Timestamp.ofTimeSecondsAndNanos(10L, 0),
        TimestampUtils.previous(Timestamp.ofTimeSecondsAndNanos(10L, 1)));
  }