提交 1814f24d authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add constant DateTimeUtils.UTC

上级 95bc8bb4
...@@ -1926,7 +1926,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -1926,7 +1926,7 @@ public class Function extends Expression implements FunctionCall {
default: default:
break; break;
} }
calendar = DateTimeUtils.createGregorianCalendar(TimeZone.getTimeZone("UTC")); calendar = DateTimeUtils.createGregorianCalendar(DateTimeUtils.UTC);
calendar.setTimeInMillis(t1); calendar.setTimeInMillis(t1);
int year1 = calendar.get(Calendar.YEAR); int year1 = calendar.get(Calendar.YEAR);
int month1 = calendar.get(Calendar.MONTH); int month1 = calendar.get(Calendar.MONTH);
......
...@@ -31,6 +31,7 @@ import org.h2.message.DbException; ...@@ -31,6 +31,7 @@ import org.h2.message.DbException;
import org.h2.server.Service; import org.h2.server.Service;
import org.h2.server.ShutdownHandler; import org.h2.server.ShutdownHandler;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.util.DateTimeUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.MathUtils; import org.h2.util.MathUtils;
import org.h2.util.NetUtils; import org.h2.util.NetUtils;
...@@ -257,7 +258,7 @@ public class WebServer implements Service { ...@@ -257,7 +258,7 @@ public class WebServer implements Service {
if (startDateTime == null) { if (startDateTime == null) {
SimpleDateFormat format = new SimpleDateFormat( SimpleDateFormat format = new SimpleDateFormat(
"EEE, d MMM yyyy HH:mm:ss z", new Locale("en", "")); "EEE, d MMM yyyy HH:mm:ss z", new Locale("en", ""));
format.setTimeZone(TimeZone.getTimeZone("GMT")); format.setTimeZone(DateTimeUtils.UTC);
startDateTime = format.format(System.currentTimeMillis()); startDateTime = format.format(System.currentTimeMillis());
} }
return startDateTime; return startDateTime;
......
...@@ -35,6 +35,11 @@ public class DateTimeUtils { ...@@ -35,6 +35,11 @@ public class DateTimeUtils {
*/ */
public static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L; public static final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000L;
/**
* UTC time zone.
*/
public static final TimeZone UTC = TimeZone.getTimeZone("UTC");
private static final long NANOS_PER_DAY = MILLIS_PER_DAY * 1000000; private static final long NANOS_PER_DAY = MILLIS_PER_DAY * 1000000;
private static final int SHIFT_YEAR = 9; private static final int SHIFT_YEAR = 9;
......
...@@ -172,7 +172,7 @@ public class ValueTimestamp extends Value { ...@@ -172,7 +172,7 @@ public class ValueTimestamp extends Value {
int timeEnd = s.length(); int timeEnd = s.length();
TimeZone tz = null; TimeZone tz = null;
if (s.endsWith("Z")) { if (s.endsWith("Z")) {
tz = TimeZone.getTimeZone("UTC"); tz = DateTimeUtils.UTC;
timeEnd--; timeEnd--;
} else { } else {
int timeZoneStart = s.indexOf('+', dateEnd + 1); int timeZoneStart = s.indexOf('+', dateEnd + 1);
......
...@@ -40,8 +40,6 @@ public class ValueTimestampTimeZone extends Value { ...@@ -40,8 +40,6 @@ public class ValueTimestampTimeZone extends Value {
*/ */
static final int DEFAULT_SCALE = 10; static final int DEFAULT_SCALE = 10;
private static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");
/** /**
* A bit field with bits for the year, month, and day (see DateTimeUtils for * A bit field with bits for the year, month, and day (see DateTimeUtils for
* encoding) * encoding)
...@@ -165,7 +163,7 @@ public class ValueTimestampTimeZone extends Value { ...@@ -165,7 +163,7 @@ public class ValueTimestampTimeZone extends Value {
} }
if (tz != null) { if (tz != null) {
long millis = DateTimeUtils long millis = DateTimeUtils
.convertDateValueToMillis(GMT_TIMEZONE, dateValue); .convertDateValueToMillis(DateTimeUtils.UTC, dateValue);
tzMinutes = (short) (tz.getOffset(millis) / 1000 / 60); tzMinutes = (short) (tz.getOffset(millis) / 1000 / 60);
} }
} }
...@@ -294,7 +292,7 @@ public class ValueTimestampTimeZone extends Value { ...@@ -294,7 +292,7 @@ public class ValueTimestampTimeZone extends Value {
// convert to minutes and add timezone offset // convert to minutes and add timezone offset
long a = DateTimeUtils.convertDateValueToMillis( long a = DateTimeUtils.convertDateValueToMillis(
TimeZone.getTimeZone("UTC"), dateValue) / DateTimeUtils.UTC, dateValue) /
(1000L * 60L); (1000L * 60L);
long ma = timeNanos / (1000L * 1000L * 1000L * 60L); long ma = timeNanos / (1000L * 1000L * 1000L * 60L);
a += ma; a += ma;
...@@ -302,7 +300,7 @@ public class ValueTimestampTimeZone extends Value { ...@@ -302,7 +300,7 @@ public class ValueTimestampTimeZone extends Value {
// convert to minutes and add timezone offset // convert to minutes and add timezone offset
long b = DateTimeUtils.convertDateValueToMillis( long b = DateTimeUtils.convertDateValueToMillis(
TimeZone.getTimeZone("UTC"), t.dateValue) / DateTimeUtils.UTC, t.dateValue) /
(1000L * 60L); (1000L * 60L);
long mb = t.timeNanos / (1000L * 1000L * 1000L * 60L); long mb = t.timeNanos / (1000L * 1000L * 1000L * 60L);
b += mb; b += mb;
......
...@@ -352,7 +352,7 @@ public class TestDate extends TestBase { ...@@ -352,7 +352,7 @@ public class TestDate extends TestBase {
} }
private void testValidDate() { private void testValidDate() {
Calendar c = DateTimeUtils.createGregorianCalendar(TimeZone.getTimeZone("UTC")); Calendar c = DateTimeUtils.createGregorianCalendar(DateTimeUtils.UTC);
c.setLenient(false); c.setLenient(false);
for (int y = -2000; y < 3000; y++) { for (int y = -2000; y < 3000; y++) {
for (int m = -3; m <= 14; m++) { for (int m = -3; m <= 14; m++) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论