2424import java .nio .file .Path ;
2525import java .nio .file .SimpleFileVisitor ;
2626import java .nio .file .attribute .BasicFileAttributes ;
27+ import java .time .Instant ;
28+ import java .time .LocalDateTime ;
29+ import java .time .OffsetDateTime ;
30+ import java .time .ZonedDateTime ;
31+ import java .time .format .DateTimeFormatter ;
32+ import java .time .temporal .ChronoUnit ;
33+ import java .time .temporal .TemporalAccessor ;
2734import java .util .ArrayList ;
2835import java .util .Collections ;
2936import java .util .HashMap ;
@@ -64,6 +71,7 @@ private static Document parse(Path testReport) {
6471 }
6572 }
6673
74+ @ SuppressWarnings ("JavaTimeDefaultTimeZone" )
6775 private void scanTestFile (Path testReport ) {
6876 Document doc = parse (testReport );
6977 doc .getDocumentElement ().normalize ();
@@ -80,6 +88,29 @@ private void scanTestFile(Path testReport) {
8088 return ;
8189 }
8290
91+ // google sheets don't automatically recognize dates with time zone, here we reformat the date
92+ // so that it wouldn't have the time zone
93+ TemporalAccessor ta =
94+ DateTimeFormatter .ISO_DATE_TIME .parseBest (
95+ timestamp , ZonedDateTime ::from , LocalDateTime ::from );
96+ timestamp = DateTimeFormatter .ISO_LOCAL_DATE_TIME .format (ta );
97+
98+ // when test result file was modified more than 20 minutes after the time in the results file
99+ // then the test results were restored from gradle cache and the test wasn't actually executed
100+ Instant reportModified = Instant .ofEpochMilli (testReport .toFile ().lastModified ());
101+ reportModified = reportModified .minus (20 , ChronoUnit .MINUTES );
102+ Instant testExecuted = null ;
103+ if (ta instanceof ZonedDateTime ) {
104+ testExecuted = ((ZonedDateTime ) ta ).toInstant ();
105+ } else if (ta instanceof LocalDateTime ) {
106+ testExecuted = ((LocalDateTime ) ta ).toInstant (OffsetDateTime .now ().getOffset ());
107+ }
108+ if (testExecuted != null && reportModified .isAfter (testExecuted )) {
109+ System .err .println (
110+ "Ignoring " + testReport + " since it appears to be restored from gradle build cache" );
111+ return ;
112+ }
113+
83114 class TestCase {
84115 final String className ;
85116 final String name ;
0 commit comments