Skip to content

Commit ee121e5

Browse files
committed
Also fix getTime and getDate
1 parent 3ed198a commit ee121e5

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/accessor/impl/calendar/ArrowFlightJdbcTimeStampVectorAccessor.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public Date getDate(Calendar calendar) {
160160
return null;
161161
}
162162

163-
return new Date(Timestamp.valueOf(localDateTime).getTime());
163+
return new Date(getTimstampWithOffset(calendar, localDateTime).getTime());
164164
}
165165

166166
@Override
@@ -170,7 +170,7 @@ public Time getTime(Calendar calendar) {
170170
return null;
171171
}
172172

173-
return new Time(Timestamp.valueOf(localDateTime).getTime());
173+
return new Time(getTimstampWithOffset(calendar, localDateTime).getTime());
174174
}
175175

176176
@Override
@@ -179,19 +179,26 @@ public Timestamp getTimestamp(Calendar calendar) {
179179
if (localDateTime == null) {
180180
return null;
181181
}
182-
// to prevent breaking changes for those using this, apply the offset that was previously
183-
// applied in getLocalDateTime
182+
183+
return getTimstampWithOffset(calendar, localDateTime);
184+
}
185+
186+
/**
187+
* Apply offset to LocalDateTime to get a Timestamp with legacy behavior. Previously we applied
188+
* the offset to the LocalDateTime even if the underlying Vector did not have a TZ. In order to
189+
* support java.time.* accessors, we fixed this so we only apply the offset if the underlying
190+
* vector includes TZ info. In order to maintain backward compatibility, we apply the offset if
191+
* needed for getDate, getTime, and getTimestamp.
192+
*/
193+
private Timestamp getTimstampWithOffset(Calendar calendar, LocalDateTime localDateTime) {
184194
if (calendar != null && !isZoned) {
185195
TimeZone timeZone = calendar.getTimeZone();
186196
long millis = Timestamp.valueOf(localDateTime).getTime();
187197
localDateTime =
188198
localDateTime.minus(
189199
timeZone.getOffset(millis) - this.timeZone.getOffset(millis), ChronoUnit.MILLIS);
190-
191-
return Timestamp.valueOf(localDateTime);
192-
} else {
193-
return Timestamp.valueOf(localDateTime);
194200
}
201+
return Timestamp.valueOf(localDateTime);
195202
}
196203

197204
protected static TimeUnit getTimeUnitForVector(TimeStampVector vector) {

0 commit comments

Comments
 (0)