Skip to content

Commit

Permalink
Fix creation of java.sql dates
Browse files Browse the repository at this point in the history
The java.sql.Date constructor specifies that the year must be the year
minus 1900. And the java.sql.Timestamp constructor specifies that the
year must be the year minus 1990.
  • Loading branch information
aVolpe committed Jul 15, 2016
1 parent 1134035 commit 3f83323
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ private Sale createSale(Customer customer, int year, int month, int day, int hou
// SQL and JPA has some issues with timezones, so we'll manually
// set the years and stuff for dates using deprecated methods to
// ensure we consistently get certain values in the database.
java.sql.Date sqlDate = new java.sql.Date(year, month, day);
java.sql.Date sqlDate = new java.sql.Date(year - 1900, month, day);
java.sql.Time sqlTime = new java.sql.Time(hour, 0, 0);
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(year, month, day, hour, 0, 0, 0);
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(year - 1900, month, day, hour, 0, 0, 0);

CreditCard creditCard = new CreditCard();
creditCard.setName(customer.getName());
Expand Down
8 changes: 4 additions & 4 deletions jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public void testCalendar()
@Test
public void testSqlDate()
{
java.sql.Date val = new java.sql.Date(2002, 1, 1);
java.sql.Date val2 = new java.sql.Date(2003, 1, 1);
java.sql.Date val = new java.sql.Date(2002 - 1900, 1, 1);
java.sql.Date val2 = new java.sql.Date(2003 - 1900, 1, 1);
List<Pair<Customer, java.sql.Date>> sales = streams.streamAll(em, Sale.class)
.where(s -> s.getSqlDate().before(val) || s.getSqlDate().equals(val2))
.select(s -> new Pair<>(s.getCustomer(), s.getSqlDate()))
Expand Down Expand Up @@ -201,8 +201,8 @@ public void testSqlTime()
@Test
public void testSqlTimestamp()
{
java.sql.Timestamp val = new java.sql.Timestamp(2002, 1, 1, 1, 0, 0, 0);
java.sql.Timestamp val2 = new java.sql.Timestamp(2003, 1, 1, 1, 0, 0, 0);
java.sql.Timestamp val = new java.sql.Timestamp(2002 - 1900, 1, 1, 1, 0, 0, 0);
java.sql.Timestamp val2 = new java.sql.Timestamp(2003 - 1900, 1, 1, 1, 0, 0, 0);
List<Pair<Customer, java.sql.Timestamp>> sales = streams.streamAll(em, Sale.class)
.where(s -> s.getSqlTimestamp().before(val) || s.getSqlTimestamp().equals(val2))
.select(s -> new Pair<>(s.getCustomer(), s.getSqlTimestamp()))
Expand Down

0 comments on commit 3f83323

Please sign in to comment.