Skip to content

Commit f25dbd1

Browse files
committed
Stabilize time check
1 parent 61f3a32 commit f25dbd1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/test/java/org/kohsuke/github/GitHubStaticTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public void timeRoundTrip() throws Exception {
2626
Date instantSeconds = Date.from(instantNow.truncatedTo(ChronoUnit.SECONDS));
2727
Date instantMillis = Date.from(instantNow.truncatedTo(ChronoUnit.MILLIS));
2828

29+
// if we happen to land exactly on zero milliseconds, add 1 milli
30+
if (instantSeconds.equals(instantMillis)) {
31+
instantMillis = Date.from(instantNow.plusMillis(1).truncatedTo(ChronoUnit.MILLIS));
32+
}
33+
2934
// TODO: other formats
3035
String instantFormatSlash = formatDate(instantMillis, "yyyy/MM/dd HH:mm:ss ZZZZ");
3136
String instantFormatDash = formatDate(instantMillis, "yyyy-MM-dd'T'HH:mm:ss'Z'");
@@ -40,6 +45,7 @@ public void timeRoundTrip() throws Exception {
4045
assertThat(instantSeconds,
4146
equalTo(GitHub.parseDate(GitHub.printDate(instantSeconds))));
4247

48+
// printDate will truncate to the nearest second, so it should not be equal
4349
assertThat(instantMillis,
4450
not(equalTo(GitHub.parseDate(GitHub.printDate(instantMillis)))));
4551

@@ -49,6 +55,7 @@ public void timeRoundTrip() throws Exception {
4955
assertThat(instantSeconds,
5056
equalTo(GitHub.parseDate(instantFormatDash)));
5157

58+
// This parser does not truncate to the nearest second, so it will be equal
5259
assertThat(instantMillis,
5360
equalTo(GitHub.parseDate(instantFormatMillis)));
5461

0 commit comments

Comments
 (0)