public static Instant windmillToHarnessTimestamp(long timestampUs) {
    // Windmill should never send us an unknown timestamp.
    Preconditions.checkArgument(timestampUs != Long.MIN_VALUE);
    Instant result = new Instant(divideAndRoundDown(timestampUs, 1000));
    if (result.isBefore(BoundedWindow.TIMESTAMP_MIN_VALUE)) {
      return BoundedWindow.TIMESTAMP_MIN_VALUE;
    }
    if (result.isAfter(BoundedWindow.TIMESTAMP_MAX_VALUE)) {
      // End of time.
      return BoundedWindow.TIMESTAMP_MAX_VALUE;
    }
    return result;
  }
@Test
  public void testWindmillToHarnessTimestamp() {
    assertEquals(BoundedWindow.TIMESTAMP_MAX_VALUE, windmillToHarnessTimestamp(Long.MAX_VALUE));
    assertEquals(
        BoundedWindow.TIMESTAMP_MAX_VALUE, windmillToHarnessTimestamp(Long.MAX_VALUE - 17));
    assertEquals(new Instant(16), windmillToHarnessWatermark(16999));
    assertEquals(new Instant(17), windmillToHarnessTimestamp(17120));
    assertEquals(new Instant(17), windmillToHarnessTimestamp(17000));
    assertEquals(new Instant(-17), windmillToHarnessTimestamp(-16987));
    assertEquals(new Instant(-17), windmillToHarnessTimestamp(-17000));
    assertEquals(new Instant(-18), windmillToHarnessTimestamp(-17001));
    assertEquals(BoundedWindow.TIMESTAMP_MIN_VALUE, windmillToHarnessTimestamp(Long.MIN_VALUE + 1));
    assertEquals(BoundedWindow.TIMESTAMP_MIN_VALUE, windmillToHarnessTimestamp(Long.MIN_VALUE + 2));
    // Long.MIN_VALUE = -9223372036854775808, need to add 1808 microseconds to get to next
    // millisecond returned by Beam.
    assertEquals(
        BoundedWindow.TIMESTAMP_MIN_VALUE.plus(Duration.millis(1)),
        windmillToHarnessTimestamp(Long.MIN_VALUE + 1808));
    assertEquals(
        BoundedWindow.TIMESTAMP_MIN_VALUE, windmillToHarnessTimestamp(Long.MIN_VALUE + 1807));
  }