Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit a6de377

Browse files
committed
[ARROW-7301][Java] Remove division in time conversion
1 parent be73192 commit a6de377

File tree

1 file changed

+3
-8
lines changed
  • java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer

1 file changed

+3
-8
lines changed

java/adapter/jdbc/src/main/java/org/apache/arrow/adapter/jdbc/consumer/DateConsumer.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,13 @@
3434
*/
3535
public class DateConsumer {
3636

37-
/**
38-
* The number of milli-seconds in a day.
39-
*/
40-
public static final long MILLIS_PER_DAY = TimeUnit.DAYS.toMillis(1);
41-
4237
public static final int MAX_DAY;
4338

4439
static {
4540
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
4641
try {
4742
java.util.Date date = dateFormat.parse("9999-12-31");
48-
MAX_DAY = (int) (date.getTime() / MILLIS_PER_DAY);
43+
MAX_DAY = (int) TimeUnit.MILLISECONDS.toDays(date.getTime());
4944
} catch (ParseException e) {
5045
throw new IllegalArgumentException("Failed to parse max day", e);
5146
}
@@ -90,7 +85,7 @@ public void consume(ResultSet resultSet) throws SQLException {
9085
Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) :
9186
resultSet.getDate(columnIndexInResultSet, calendar);
9287
if (!resultSet.wasNull()) {
93-
int day = (int) (date.getTime() / MILLIS_PER_DAY);
88+
int day = (int) TimeUnit.MILLISECONDS.toDays(date.getTime());
9489
if (day < 0 || day > MAX_DAY) {
9590
throw new IllegalArgumentException("Day overflow: " + day);
9691
}
@@ -126,7 +121,7 @@ public NonNullableDateConsumer(DateDayVector vector, int index, Calendar calenda
126121
public void consume(ResultSet resultSet) throws SQLException {
127122
Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) :
128123
resultSet.getDate(columnIndexInResultSet, calendar);
129-
int day = (int) (date.getTime() / MILLIS_PER_DAY);
124+
int day = (int) TimeUnit.MILLISECONDS.toDays(date.getTime());
130125
if (day < 0 || day > MAX_DAY) {
131126
throw new IllegalArgumentException("Day overflow: " + day);
132127
}

0 commit comments

Comments
 (0)