|
34 | 34 | */ |
35 | 35 | public class DateConsumer { |
36 | 36 |
|
37 | | - /** |
38 | | - * The number of milli-seconds in a day. |
39 | | - */ |
40 | | - public static final long MILLIS_PER_DAY = TimeUnit.DAYS.toMillis(1); |
41 | | - |
42 | 37 | public static final int MAX_DAY; |
43 | 38 |
|
44 | 39 | static { |
45 | 40 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
46 | 41 | try { |
47 | 42 | 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()); |
49 | 44 | } catch (ParseException e) { |
50 | 45 | throw new IllegalArgumentException("Failed to parse max day", e); |
51 | 46 | } |
@@ -90,7 +85,7 @@ public void consume(ResultSet resultSet) throws SQLException { |
90 | 85 | Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) : |
91 | 86 | resultSet.getDate(columnIndexInResultSet, calendar); |
92 | 87 | if (!resultSet.wasNull()) { |
93 | | - int day = (int) (date.getTime() / MILLIS_PER_DAY); |
| 88 | + int day = (int) TimeUnit.MILLISECONDS.toDays(date.getTime()); |
94 | 89 | if (day < 0 || day > MAX_DAY) { |
95 | 90 | throw new IllegalArgumentException("Day overflow: " + day); |
96 | 91 | } |
@@ -126,7 +121,7 @@ public NonNullableDateConsumer(DateDayVector vector, int index, Calendar calenda |
126 | 121 | public void consume(ResultSet resultSet) throws SQLException { |
127 | 122 | Date date = calendar == null ? resultSet.getDate(columnIndexInResultSet) : |
128 | 123 | resultSet.getDate(columnIndexInResultSet, calendar); |
129 | | - int day = (int) (date.getTime() / MILLIS_PER_DAY); |
| 124 | + int day = (int) TimeUnit.MILLISECONDS.toDays(date.getTime()); |
130 | 125 | if (day < 0 || day > MAX_DAY) { |
131 | 126 | throw new IllegalArgumentException("Day overflow: " + day); |
132 | 127 | } |
|
0 commit comments