New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1390 LocalDateTime
string serialization
#1391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -830,9 +830,8 @@ public synchronized String toString(LocalDateTime localDateTime) { | |
return "-infinity"; | ||
} | ||
|
||
// LocalDateTime is always passed with time zone so backend can decide between timestamp and timestamptz | ||
ZonedDateTime zonedDateTime = localDateTime.atZone(getDefaultTz().toZoneId()); | ||
return toString(zonedDateTime.toOffsetDateTime()); | ||
OffsetDateTime offsetDateTime = localDateTime.atOffset(ZoneOffset.UTC); | ||
return toString(offsetDateTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This renders something like Consider use-cases
If this needs to stay this way, please add some explanation. |
||
} | ||
|
||
private static void appendDate(StringBuilder sb, LocalDate localDate) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
import static org.junit.Assume.assumeTrue; | ||
|
||
import org.postgresql.test.TestUtil; | ||
import org.postgresql.test.jdbc2.BaseTest4; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
@@ -38,10 +40,12 @@ | |
import java.time.temporal.ChronoField; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.TimeZone; | ||
|
||
public class SetObject310Test { | ||
@RunWith(Parameterized.class) | ||
public class SetObject310Test extends BaseTest4 { | ||
private static final TimeZone saveTZ = TimeZone.getDefault(); | ||
|
||
public static final DateTimeFormatter LOCAL_TIME_FORMATTER = | ||
|
@@ -64,11 +68,22 @@ public class SetObject310Test { | |
.withResolverStyle(ResolverStyle.LENIENT) | ||
.withChronology(IsoChronology.INSTANCE); | ||
|
||
private Connection con; | ||
public SetObject310Test(BaseTest4.BinaryMode binaryMode) { | ||
setBinaryMode(binaryMode); | ||
} | ||
|
||
@Parameterized.Parameters(name = "binary = {0}") | ||
public static Iterable<Object[]> data() { | ||
Collection<Object[]> ids = new ArrayList<Object[]>(); | ||
for (BaseTest4.BinaryMode binaryMode : BaseTest4.BinaryMode.values()) { | ||
ids.add(new Object[]{binaryMode}); | ||
} | ||
return ids; | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
con = TestUtil.openDB(); | ||
super.setUp(); | ||
TestUtil.createTable(con, "table1", "timestamp_without_time_zone_column timestamp without time zone," | ||
+ "timestamp_with_time_zone_column timestamp with time zone," | ||
+ "date_column date," | ||
|
@@ -81,7 +96,7 @@ public void setUp() throws Exception { | |
public void tearDown() throws SQLException { | ||
TimeZone.setDefault(saveTZ); | ||
TestUtil.dropTable(con, "table1"); | ||
TestUtil.closeDB(con); | ||
super.tearDown(); | ||
} | ||
|
||
private void insert(Object data, String columnName, Integer type) throws SQLException { | ||
|
@@ -199,7 +214,7 @@ public void testSetLocalDateTime() throws SQLException { | |
ZoneId zone = ZoneId.of(zoneId); | ||
for (String date : datesToTest) { | ||
LocalDateTime localDateTime = LocalDateTime.parse(date); | ||
String expected = localDateTime.atZone(zone) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO it is correct this was changed, asserting that I think the tests should be changed though to not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense.. care to provide a PR ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm looking at this and wondering why we are using timezones at all on LocalDateTime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can have a look. I'll have to check if it breaks any tests. It may take a few days. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not worth your time until we decide how to deal with this. |
||
String expected = localDateTime | ||
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) | ||
.replace('T', ' '); | ||
localTimestamps(zone, localDateTime, expected); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should do the opposite there.
LocalDateTime
has no time zone, we should not make up one. I would simply not send a time zone if we don't have one.