Skip to content

Commit bd0f6e4

Browse files
committed
fix(bigquery-jdbc): update getSafeCalendar and convertTimeWithCalendar in BigQueryTypeCoercionUtility
1 parent 4c177b3 commit bd0f6e4

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryTypeCoercionUtility.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,15 @@ static Time convertTimeWithCalendar(Time time, Calendar cal) {
8080
if (cal == null) {
8181
return time;
8282
}
83-
LocalTime localTime = time.toLocalTime();
84-
ZonedDateTime zdt =
85-
localTime.atDate(LocalDate.of(1970, 1, 1)).atZone(cal.getTimeZone().toZoneId());
86-
return new Time(zdt.toInstant().toEpochMilli());
83+
Calendar defaultCal = Calendar.getInstance();
84+
defaultCal.setTime(time);
85+
86+
Calendar targetCal = getSafeCalendar(cal);
87+
targetCal.set(Calendar.HOUR_OF_DAY, defaultCal.get(Calendar.HOUR_OF_DAY));
88+
targetCal.set(Calendar.MINUTE, defaultCal.get(Calendar.MINUTE));
89+
targetCal.set(Calendar.SECOND, defaultCal.get(Calendar.SECOND));
90+
targetCal.set(Calendar.MILLISECOND, defaultCal.get(Calendar.MILLISECOND));
91+
return new Time(targetCal.getTimeInMillis());
8792
}
8893

8994
/**

0 commit comments

Comments
 (0)