@Test void testSerializeEpochTimestampAsIsoDateTime() { long timestamp = 0; long lastTimestampToCheck = LocalDateTime.now() .plus(1, ChronoUnit.YEARS) .toInstant(ZoneOffset.UTC) .toEpochMilli(); long interval = 997 * 61 * 61; for (; timestamp <= lastTimestampToCheck; timestamp += interval) { assertDateFormattingIsCorrect(Instant.ofEpochMilli(timestamp)); } StringBuilder builder = new StringBuilder(); dateSerializer.serializeEpochTimestampAsIsoDateTime(builder, 1565093352375L); System.out.println(builder); builder.setLength(0); dateSerializer.serializeEpochTimestampAsIsoDateTime(builder, 1565093352379L); System.out.println(builder); builder.setLength(0); dateSerializer.serializeEpochTimestampAsIsoDateTime(builder, 1565100520199L); System.out.println(builder); }
void serializeEpochTimestampAsIsoDateTime(StringBuilder builder, long epochTimestamp) { CachedDate cachedDateLocal = cachedDate; if (cachedDateLocal == null || !cachedDateLocal.isDateCached(epochTimestamp)) { cachedDate = cachedDateLocal = new CachedDate(epochTimestamp); } builder.append(cachedDateLocal.getCachedDateIso()); builder.append(TIME_SEPARATOR); long remainder = epochTimestamp % MILLIS_PER_DAY; serializeWithLeadingZero(builder, remainder / MILLIS_PER_HOUR, 2); builder.append(COLON); remainder %= MILLIS_PER_HOUR; serializeWithLeadingZero(builder, remainder / MILLIS_PER_MINUTE, 2); builder.append(COLON); remainder %= MILLIS_PER_MINUTE; serializeWithLeadingZero(builder, remainder / MILLIS_PER_SECOND, 2); builder.append(DOT); remainder %= MILLIS_PER_SECOND; serializeWithLeadingZero(builder, remainder, 3); builder.append(TIME_ZONE_SEPARATOR); }
TimestampSerializer { void serializeEpochTimestampAsIsoDateTime(StringBuilder builder, long epochTimestamp) { CachedDate cachedDateLocal = cachedDate; if (cachedDateLocal == null || !cachedDateLocal.isDateCached(epochTimestamp)) { cachedDate = cachedDateLocal = new CachedDate(epochTimestamp); } builder.append(cachedDateLocal.getCachedDateIso()); builder.append(TIME_SEPARATOR); long remainder = epochTimestamp % MILLIS_PER_DAY; serializeWithLeadingZero(builder, remainder / MILLIS_PER_HOUR, 2); builder.append(COLON); remainder %= MILLIS_PER_HOUR; serializeWithLeadingZero(builder, remainder / MILLIS_PER_MINUTE, 2); builder.append(COLON); remainder %= MILLIS_PER_MINUTE; serializeWithLeadingZero(builder, remainder / MILLIS_PER_SECOND, 2); builder.append(DOT); remainder %= MILLIS_PER_SECOND; serializeWithLeadingZero(builder, remainder, 3); builder.append(TIME_ZONE_SEPARATOR); } }
TimestampSerializer { void serializeEpochTimestampAsIsoDateTime(StringBuilder builder, long epochTimestamp) { CachedDate cachedDateLocal = cachedDate; if (cachedDateLocal == null || !cachedDateLocal.isDateCached(epochTimestamp)) { cachedDate = cachedDateLocal = new CachedDate(epochTimestamp); } builder.append(cachedDateLocal.getCachedDateIso()); builder.append(TIME_SEPARATOR); long remainder = epochTimestamp % MILLIS_PER_DAY; serializeWithLeadingZero(builder, remainder / MILLIS_PER_HOUR, 2); builder.append(COLON); remainder %= MILLIS_PER_HOUR; serializeWithLeadingZero(builder, remainder / MILLIS_PER_MINUTE, 2); builder.append(COLON); remainder %= MILLIS_PER_MINUTE; serializeWithLeadingZero(builder, remainder / MILLIS_PER_SECOND, 2); builder.append(DOT); remainder %= MILLIS_PER_SECOND; serializeWithLeadingZero(builder, remainder, 3); builder.append(TIME_ZONE_SEPARATOR); }  }
TimestampSerializer { void serializeEpochTimestampAsIsoDateTime(StringBuilder builder, long epochTimestamp) { CachedDate cachedDateLocal = cachedDate; if (cachedDateLocal == null || !cachedDateLocal.isDateCached(epochTimestamp)) { cachedDate = cachedDateLocal = new CachedDate(epochTimestamp); } builder.append(cachedDateLocal.getCachedDateIso()); builder.append(TIME_SEPARATOR); long remainder = epochTimestamp % MILLIS_PER_DAY; serializeWithLeadingZero(builder, remainder / MILLIS_PER_HOUR, 2); builder.append(COLON); remainder %= MILLIS_PER_HOUR; serializeWithLeadingZero(builder, remainder / MILLIS_PER_MINUTE, 2); builder.append(COLON); remainder %= MILLIS_PER_MINUTE; serializeWithLeadingZero(builder, remainder / MILLIS_PER_SECOND, 2); builder.append(DOT); remainder %= MILLIS_PER_SECOND; serializeWithLeadingZero(builder, remainder, 3); builder.append(TIME_ZONE_SEPARATOR); }   }
TimestampSerializer { void serializeEpochTimestampAsIsoDateTime(StringBuilder builder, long epochTimestamp) { CachedDate cachedDateLocal = cachedDate; if (cachedDateLocal == null || !cachedDateLocal.isDateCached(epochTimestamp)) { cachedDate = cachedDateLocal = new CachedDate(epochTimestamp); } builder.append(cachedDateLocal.getCachedDateIso()); builder.append(TIME_SEPARATOR); long remainder = epochTimestamp % MILLIS_PER_DAY; serializeWithLeadingZero(builder, remainder / MILLIS_PER_HOUR, 2); builder.append(COLON); remainder %= MILLIS_PER_HOUR; serializeWithLeadingZero(builder, remainder / MILLIS_PER_MINUTE, 2); builder.append(COLON); remainder %= MILLIS_PER_MINUTE; serializeWithLeadingZero(builder, remainder / MILLIS_PER_SECOND, 2); builder.append(DOT); remainder %= MILLIS_PER_SECOND; serializeWithLeadingZero(builder, remainder, 3); builder.append(TIME_ZONE_SEPARATOR); }    }