Skip to content

Commit b4674c0

Browse files
authored
KAFKA-18585 Fix fail test ValuesTest#shouldConvertDateValues (#18611)
Reviewers: Divij Vaidya <[email protected]>, Andrew Schofield <[email protected]>
1 parent 256ccd0 commit b4674c0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

connect/api/src/test/java/org/apache/kafka/connect/data/ValuesTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,9 @@ public void shouldConvertTimeValues() {
887887

888888
@Test
889889
public void shouldConvertDateValues() {
890-
java.util.Date current = new java.util.Date();
890+
LocalDateTime localTime = LocalDateTime.now();
891+
ZoneOffset zoneOffset = ZoneId.systemDefault().getRules().getOffset(localTime);
892+
java.util.Date current = new java.util.Date(localTime.toEpochSecond(zoneOffset) * 1000);
891893
long currentMillis = current.getTime() % MILLIS_PER_DAY;
892894
long days = current.getTime() / MILLIS_PER_DAY;
893895

@@ -901,8 +903,10 @@ public void shouldConvertDateValues() {
901903
assertEquals(currentDate, d2);
902904

903905
// ISO8601 strings - accept a string matching pattern "yyyy-MM-dd"
906+
LocalDateTime localTimeTruncated = localTime.truncatedTo(ChronoUnit.DAYS);
904907
java.util.Date d3 = Values.convertToDate(Date.SCHEMA, LocalDate.ofEpochDay(days).format(DateTimeFormatter.ISO_LOCAL_DATE));
905-
assertEquals(currentDate, d3);
908+
LocalDateTime date3 = LocalDateTime.ofInstant(Instant.ofEpochMilli(d3.getTime()), ZoneId.systemDefault());
909+
assertEquals(localTimeTruncated, date3);
906910

907911
// Days as string
908912
java.util.Date d4 = Values.convertToDate(Date.SCHEMA, Long.toString(days));

0 commit comments

Comments
 (0)