From 3f83323bae368be0f2bbd999d0516b63a66d0c5c Mon Sep 17 00:00:00 2001 From: Arturo Volpe Date: Thu, 14 Jul 2016 19:34:53 -0400 Subject: [PATCH] Fix creation of java.sql dates 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. --- jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java | 4 ++-- jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java b/jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java index eb1215cd..63d8df7c 100644 --- a/jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java +++ b/jinq-jpa/test/org/jinq/jpa/CreateJpaDb.java @@ -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()); diff --git a/jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java b/jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java index d8efb2c2..d155049f 100644 --- a/jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java +++ b/jinq-jpa/test/org/jinq/jpa/JinqJPATypesTest.java @@ -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> sales = streams.streamAll(em, Sale.class) .where(s -> s.getSqlDate().before(val) || s.getSqlDate().equals(val2)) .select(s -> new Pair<>(s.getCustomer(), s.getSqlDate())) @@ -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> sales = streams.streamAll(em, Sale.class) .where(s -> s.getSqlTimestamp().before(val) || s.getSqlTimestamp().equals(val2)) .select(s -> new Pair<>(s.getCustomer(), s.getSqlTimestamp()))