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