提交 44847676 authored 作者: Thomas Mueller's avatar Thomas Mueller

There is a problem when opening a database file in a timezone that has different…

There is a problem when opening a database file in a timezone that has different daylight saving rules
上级 1534f364
...@@ -92,7 +92,7 @@ public class DateTimeUtils { ...@@ -92,7 +92,7 @@ public class DateTimeUtils {
cal.set(Calendar.ERA, GregorianCalendar.AD); cal.set(Calendar.ERA, GregorianCalendar.AD);
// month is 0 based // month is 0 based
cal.set(DEFAULT_YEAR, DEFAULT_MONTH - 1, DEFAULT_DAY); cal.set(DEFAULT_YEAR, DEFAULT_MONTH - 1, DEFAULT_DAY);
time = cal.getTime().getTime(); time = cal.getTimeInMillis();
} }
return new Time(time); return new Time(time);
} }
......
...@@ -234,8 +234,6 @@ public class Transfer { ...@@ -234,8 +234,6 @@ public class Transfer {
if (len == -1) { if (len == -1) {
return null; return null;
} }
// TODO optimize: StringBuilder is synchronized, maybe use a char array
// (but that means more memory)
StringBuilder buff = new StringBuilder(len); StringBuilder buff = new StringBuilder(len);
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
buff.append(in.readChar()); buff.append(in.readChar());
......
...@@ -60,6 +60,7 @@ public class TestDateStorage extends TestBase { ...@@ -60,6 +60,7 @@ public class TestDateStorage extends TestBase {
ArrayList<TimeZone> distinct = TestDate.getDistinctTimeZones(); ArrayList<TimeZone> distinct = TestDate.getDistinctTimeZones();
try { try {
for (TimeZone tz : distinct) { for (TimeZone tz : distinct) {
println("insert using " + tz.getID());
TimeZone.setDefault(tz); TimeZone.setDefault(tz);
DateTimeUtils.resetCalendar(); DateTimeUtils.resetCalendar();
conn = getConnection(db); conn = getConnection(db);
...@@ -75,6 +76,7 @@ public class TestDateStorage extends TestBase { ...@@ -75,6 +76,7 @@ public class TestDateStorage extends TestBase {
} }
printTime("inserted"); printTime("inserted");
for (TimeZone target : distinct) { for (TimeZone target : distinct) {
println("select from " + target.getID());
if ("Pacific/Kiritimati".equals(target)) { if ("Pacific/Kiritimati".equals(target)) {
// there is a problem with this time zone, but it seems // there is a problem with this time zone, but it seems
// unrelated to this database (possibly wrong timezone // unrelated to this database (possibly wrong timezone
...@@ -126,13 +128,17 @@ public class TestDateStorage extends TestBase { ...@@ -126,13 +128,17 @@ public class TestDateStorage extends TestBase {
} }
private void testAllTimeZones() throws SQLException { private void testAllTimeZones() throws SQLException {
if (config.networked) {
return;
}
Connection conn = getConnection("date"); Connection conn = getConnection("date");
TimeZone defaultTimeZone = TimeZone.getDefault(); TimeZone defaultTimeZone = TimeZone.getDefault();
PreparedStatement prep = conn.prepareStatement("CALL CAST(? AS DATE)"); PreparedStatement prep = conn.prepareStatement("CALL CAST(? AS DATE)");
try { try {
String[] ids = TimeZone.getAvailableIDs(); ArrayList<TimeZone> distinct = TestDate.getDistinctTimeZones();
for (int i = 0; i < ids.length; i++) { for (TimeZone tz : distinct) {
TimeZone.setDefault(TimeZone.getTimeZone(ids[i])); println(tz.getID());
TimeZone.setDefault(tz);
DateTimeUtils.resetCalendar(); DateTimeUtils.resetCalendar();
for (int d = 101; d < 129; d++) { for (int d = 101; d < 129; d++) {
test(prep, d); test(prep, d);
...@@ -162,10 +168,10 @@ public class TestDateStorage extends TestBase { ...@@ -162,10 +168,10 @@ public class TestDateStorage extends TestBase {
time += 1000; time += 1000;
plus += 1000; plus += 1000;
} }
// if (!date.toString().equals(s)) { if (!date.toString().equals(s)) {
// println(TimeZone.getDefault().getDisplayName() + " " + s + " <> " + date.toString()); println(TimeZone.getDefault().getDisplayName() + " " + s + " <> " + date.toString());
// return; return;
// } }
prep.setString(1, s); prep.setString(1, s);
ResultSet rs = prep.executeQuery(); ResultSet rs = prep.executeQuery();
rs.next(); rs.next();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论