Skip to content

Commit ddd4bb3

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

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

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

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

163-
return new Date(Timestamp.valueOf(localDateTime).getTime());
163+
if (calendar != null && !isZoned) {
164+
return new Date(getTimstampWithOffset(calendar, localDateTime).getTime());
165+
} else {
166+
return new Date(Timestamp.valueOf(localDateTime).getTime());
167+
}
164168
}
165169

166170
@Override
@@ -170,7 +174,11 @@ public Time getTime(Calendar calendar) {
170174
return null;
171175
}
172176

173-
return new Time(Timestamp.valueOf(localDateTime).getTime());
177+
if (calendar != null && !isZoned) {
178+
return new Time(getTimstampWithOffset(calendar, localDateTime).getTime());
179+
} else {
180+
return new Time(Timestamp.valueOf(localDateTime).getTime());
181+
}
174182
}
175183

176184
@Override
@@ -179,21 +187,32 @@ public Timestamp getTimestamp(Calendar calendar) {
179187
if (localDateTime == null) {
180188
return null;
181189
}
182-
// to prevent breaking changes for those using this, apply the offset that was previously
183-
// applied in getLocalDateTime
184-
if (calendar != null && !isZoned) {
185-
TimeZone timeZone = calendar.getTimeZone();
186-
long millis = Timestamp.valueOf(localDateTime).getTime();
187-
localDateTime =
188-
localDateTime.minus(
189-
timeZone.getOffset(millis) - this.timeZone.getOffset(millis), ChronoUnit.MILLIS);
190190

191-
return Timestamp.valueOf(localDateTime);
191+
if (calendar != null && !isZoned) {
192+
return getTimstampWithOffset(calendar, localDateTime);
192193
} else {
193194
return Timestamp.valueOf(localDateTime);
194195
}
195196
}
196197

198+
/**
199+
* To prevent breaking changes for those using the legacy JDBC classes, apply the offset that was
200+
* previously applied in getLocalDateTime
201+
*
202+
* @param calendar
203+
* @param localDateTime
204+
* @return
205+
*/
206+
private Timestamp getTimstampWithOffset(Calendar calendar, LocalDateTime localDateTime) {
207+
TimeZone timeZone = calendar.getTimeZone();
208+
long millis = Timestamp.valueOf(localDateTime).getTime();
209+
localDateTime =
210+
localDateTime.minus(
211+
timeZone.getOffset(millis) - this.timeZone.getOffset(millis), ChronoUnit.MILLIS);
212+
213+
return Timestamp.valueOf(localDateTime);
214+
}
215+
197216
protected static TimeUnit getTimeUnitForVector(TimeStampVector vector) {
198217
ArrowType.Timestamp arrowType =
199218
(ArrowType.Timestamp) vector.getField().getFieldType().getType();

0 commit comments

Comments
 (0)