Skip to content

Commit

Permalink
Fix epoch day to java.sql.Date conversion
Browse files Browse the repository at this point in the history
The original conversion returned wrong result in JVM with time zone that
had shift on 1970-01-01 00:00:00 (e.g. `America/Bahia_Banderas`).
  • Loading branch information
findepi committed Mar 19, 2018
1 parent caf4c9a commit 4bbf9aa
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
import java.math.BigInteger;
import java.sql.Date;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -559,9 +559,7 @@ private static Date intToDate(Integer input)
if (input == null) {
return null;
}
Date date = new Date(0);
date.setTime(TimeUnit.DAYS.toMillis(input));
return date;
return Date.valueOf(LocalDate.ofEpochDay(input));
}

private static SqlDate intToSqlDate(Integer input)
Expand Down

0 comments on commit 4bbf9aa

Please sign in to comment.