record ms precision in timestamps
MODIFY
analytics-tests/src/test/java/com/segment/analytics/BatchPayloadWriterTest.java
analytics-tests/src/test/java/com/segment/analytics/BatchPayloadWriterTest.java
@@ -51,9 +51,12 @@ public class BatchPayloadWriterTest {
.endObject()
.close();
+ // todo: inject a fake clock. for now we'll compare a lower precision.
+ String date = toISO8601Date(new Date());
+ String expectedDate = date.substring(0, date.length() - 8);
+
assertThat(byteArrayOutputStream.toString()) //
- .isEqualTo("{\"batch\":[qaz],\"sentAt\":\"" + toISO8601Date(new Date()) + "\"}")
- .overridingErrorMessage("its ok if this failed close to midnight!");
+ .contains("{\"batch\":[qaz],\"sentAt\":\"" + expectedDate);
}
@Test public void batchPayloadWriterFailsForNoItem() throws IOException {

MODIFY
analytics/src/main/java/com/segment/analytics/internal/Utils.java
analytics/src/main/java/com/segment/analytics/internal/Utils.java
@@ -81,7 +81,7 @@ public final class Utils {
private static final ThreadLocal<DateFormat> ISO_8601_DATE_FORMAT =
new ThreadLocal<DateFormat>() {
@Override protected DateFormat initialValue() {
- return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US);
+ return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
}
};

record ms precision in timestamps