|
27 | 27 | import java.time.LocalDate;
|
28 | 28 | import java.time.LocalDateTime;
|
29 | 29 | import java.time.LocalTime;
|
30 |
| -import java.time.OffsetDateTime; |
31 | 30 | import java.util.Calendar;
|
32 | 31 | import java.util.Map;
|
33 | 32 | import java.util.function.Function;
|
@@ -291,38 +290,18 @@ public Time getTime(String columnLabel, Calendar cal) {
|
291 | 290 |
|
292 | 291 | @Override
|
293 | 292 | public Timestamp getTimestamp(String columnLabel) {
|
294 |
| - Object rawValue = row.getValue( columnLabel ); |
295 |
| - return ( wasNull = rawValue == null ) ? null : Timestamp.valueOf( toLocalDateTime( rawValue ) ); |
| 293 | + LocalDateTime rawValue = row.getLocalDateTime( columnLabel ); |
| 294 | + return ( wasNull = rawValue == null ) ? null : Timestamp.valueOf( rawValue ); |
296 | 295 | }
|
297 | 296 |
|
298 | 297 | @Override
|
299 | 298 | public Timestamp getTimestamp(String columnLabel, Calendar cal) {
|
300 |
| - Object rawValue = row.getValue( columnLabel ); |
301 |
| - return ( wasNull = rawValue == null ) ? null : Timestamp.from( toOffsetDateTime( rawValue, cal ).toInstant() ); |
| 299 | + LocalDateTime localDateTime = row.getLocalDateTime( columnLabel ); |
| 300 | + return ( wasNull = localDateTime == null ) ? null : toTimestamp( localDateTime, cal ); |
302 | 301 | }
|
303 | 302 |
|
304 |
| - private static LocalDateTime toLocalDateTime(Object rawValue) { |
305 |
| - if ( rawValue instanceof OffsetDateTime ) { |
306 |
| - return LocalDateTime.from( (OffsetDateTime) rawValue ); |
307 |
| - } |
308 |
| - else if ( rawValue instanceof LocalDateTime ) { |
309 |
| - return (LocalDateTime) rawValue; |
310 |
| - } |
311 |
| - else { |
312 |
| - throw new IllegalArgumentException( "Unexpected type: " + rawValue.getClass() ); |
313 |
| - } |
314 |
| - } |
315 |
| - |
316 |
| - private static OffsetDateTime toOffsetDateTime(Object rawValue, Calendar cal) { |
317 |
| - if ( rawValue instanceof OffsetDateTime ) { |
318 |
| - return (OffsetDateTime) rawValue; |
319 |
| - } |
320 |
| - else if ( rawValue instanceof LocalDateTime ) { |
321 |
| - return ( (LocalDateTime) rawValue ).atZone( cal.getTimeZone().toZoneId() ).toOffsetDateTime(); |
322 |
| - } |
323 |
| - else { |
324 |
| - throw new IllegalArgumentException( "Unexpected type: " + rawValue.getClass() ); |
325 |
| - } |
| 303 | + private static Timestamp toTimestamp(LocalDateTime localDateTime, Calendar cal) { |
| 304 | + return Timestamp.from( localDateTime.atZone( cal.getTimeZone().toZoneId() ).toInstant() ); |
326 | 305 | }
|
327 | 306 |
|
328 | 307 | @Override
|
@@ -800,8 +779,8 @@ public Timestamp getTimestamp(int columnIndex) {
|
800 | 779 |
|
801 | 780 | @Override
|
802 | 781 | public Timestamp getTimestamp(int columnIndex, Calendar cal) {
|
803 |
| - Object rawValue = row.getValue( columnIndex - 1 ); |
804 |
| - return ( wasNull = rawValue == null ) ? null : Timestamp.from( toOffsetDateTime( rawValue, cal ).toInstant() ); |
| 782 | + LocalDateTime localDateTime = row.getLocalDateTime( columnIndex - 1 ); |
| 783 | + return ( wasNull = localDateTime == null ) ? null : toTimestamp( localDateTime, cal ); |
805 | 784 | }
|
806 | 785 |
|
807 | 786 | @Override
|
|
0 commit comments