Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
cee57f6c
Unverified
提交
cee57f6c
authored
2月 21, 2018
作者:
Noel Grandin
提交者:
GitHub
2月 21, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #891 from katzyn/datetime
Update documentation of date-time types and clean up related code a bit
上级
bef4c05e
b58e9d40
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
26 行删除
+28
-26
help.csv
h2/src/docsrc/help/help.csv
+15
-7
Function.java
h2/src/main/org/h2/expression/Function.java
+3
-8
DateTimeUtils.java
h2/src/main/org/h2/util/DateTimeUtils.java
+10
-11
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
cee57f6c
...
...
@@ -2437,9 +2437,11 @@ REAL
"Data Types","TIME Type","
TIME
","
The time data type. The format is hh:mm:ss.
The time data type. The format is hh:mm:ss
[.nnnnnnnnn]
.
Mapped to ""java.sql.Time"". When converted to a ""java.sql.Date"", the date is set to ""1970-01-01"".
""java.time.LocalTime"" is also supported on Java 8 and later versions.
Resolution of ""java.sql.Time"" is limited to milliseconds, use ""String"" or ""java.time.LocalTime"" if you need nanosecond resolution.
","
TIME
"
...
...
@@ -2451,6 +2453,7 @@ The date data type. The format is yyyy-MM-dd.
Mapped to ""java.sql.Date"", with the time set to ""00:00:00""
(or to the next possible time if midnight doesn't exist for the given date and timezone due to a daylight saving change).
""java.time.LocalDate"" is also supported on Java 8 and later versions.
","
DATE
"
...
...
@@ -2459,9 +2462,10 @@ DATE
{ TIMESTAMP | DATETIME | SMALLDATETIME }
","
The timestamp data type. The format is yyyy-MM-dd hh:mm:ss[.nnnnnnnnn].
Stored internally as a BCD-encoded date, and nano
-
seconds since midnight.
Stored internally as a BCD-encoded date, and nanoseconds since midnight.
Mapped to ""java.sql.Timestamp"" (""java.util.Date"" is also supported).
Mapped to ""java.sql.Timestamp"" (""java.util.Date"" may be used too).
""java.time.LocalDateTime"" is also supported on Java 8 and later versions.
","
TIMESTAMP
"
...
...
@@ -2469,12 +2473,16 @@ TIMESTAMP
"Data Types","TIMESTAMP WITH TIME ZONE Type","
TIMESTAMP WITH TIME ZONE
","
VERY MUCH STILL IN TESTING.
The timestamp with time zone data type.
Stored internally as a BCD-encoded date, nano-seconds since midnight, and timezone offset in minutes.
Note that range queries on this datatype may do some weird stuff close to DST boundaries.
Stored internally as a BCD-encoded date, nanoseconds since midnight, and time zone offset in minutes.
Mapped to ""org.h2.api.TimestampWithTimeZone""
Mapped to ""org.h2.api.TimestampWithTimeZone"".
""java.time.OffsetDateTime"" and ""java.time.Instant"" are also supported on Java 8 and later versions.
Values of this data type are compared by UTC values. It means that ""2010-01-01 10:00:00+01"" is greater than ""2010-01-01 11:00:00+03"".
Conversion to ""TIMESTAMP"" uses time zone offset to get UTC time and converts it to local time using the system time zone.
Conversion from ""TIMESTAMP"" does the same operations in reverse and sets time zone offset to offset of the system time zone.
","
TIMESTAMP WITH TIME ZONE
"
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
cee57f6c
...
...
@@ -1553,17 +1553,12 @@ public class Function extends Expression implements FunctionCall {
null
:
v2
==
ValueNull
.
INSTANCE
?
null
:
v2
.
getString
();
String
tz
=
v3
==
null
?
null
:
v3
==
ValueNull
.
INSTANCE
?
null
:
v3
.
getString
();
java
.
util
.
Date
date
;
if
(
v0
instanceof
ValueTimestampTimeZone
)
{
ValueTimestampTimeZone
ts
=
(
ValueTimestampTimeZone
)
v0
;
tz
=
DateTimeUtils
.
timeZoneNameFromOffsetMins
(
ts
.
getTimeZoneOffsetMins
());
date
=
DateTimeUtils
.
convertTimestampTimeZoneToTimestamp
(
ts
.
getDateValue
(),
ts
.
getTimeNanos
(),
ts
.
getTimeZoneOffsetMins
());
}
else
{
date
=
v0
.
getTimestamp
();
tz
=
DateTimeUtils
.
timeZoneNameFromOffsetMins
(
((
ValueTimestampTimeZone
)
v0
).
getTimeZoneOffsetMins
());
}
result
=
ValueString
.
get
(
DateTimeUtils
.
formatDateTime
(
date
,
v1
.
getString
(),
locale
,
tz
),
v0
.
getTimestamp
()
,
v1
.
getString
(),
locale
,
tz
),
database
.
getMode
().
treatEmptyStringsAsNull
);
}
break
;
...
...
h2/src/main/org/h2/util/DateTimeUtils.java
浏览文件 @
cee57f6c
...
...
@@ -98,8 +98,7 @@ public class DateTimeUtils {
* use a fixed value throughout the duration of the JVM's life, rather than
* have this offset change, possibly midway through a long-running query.
*/
private
static
int
zoneOffsetMillis
=
DateTimeUtils
.
createGregorianCalendar
()
.
get
(
Calendar
.
ZONE_OFFSET
);
private
static
int
zoneOffsetMillis
=
createGregorianCalendar
().
get
(
Calendar
.
ZONE_OFFSET
);
private
DateTimeUtils
()
{
// utility class
...
...
@@ -125,7 +124,7 @@ public class DateTimeUtils {
public
static
void
resetCalendar
()
{
CACHED_CALENDAR
.
remove
();
timeZone
=
null
;
zoneOffsetMillis
=
DateTimeUtils
.
createGregorianCalendar
().
get
(
Calendar
.
ZONE_OFFSET
);
zoneOffsetMillis
=
createGregorianCalendar
().
get
(
Calendar
.
ZONE_OFFSET
);
}
/**
...
...
@@ -136,7 +135,7 @@ public class DateTimeUtils {
public
static
GregorianCalendar
getCalendar
()
{
GregorianCalendar
c
=
CACHED_CALENDAR
.
get
();
if
(
c
==
null
)
{
c
=
DateTimeUtils
.
createGregorianCalendar
();
c
=
createGregorianCalendar
();
CACHED_CALENDAR
.
set
(
c
);
}
c
.
clear
();
...
...
@@ -152,7 +151,7 @@ public class DateTimeUtils {
private
static
GregorianCalendar
getCalendar
(
TimeZone
tz
)
{
GregorianCalendar
c
=
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
.
get
();
if
(
c
==
null
||
!
c
.
getTimeZone
().
equals
(
tz
))
{
c
=
DateTimeUtils
.
createGregorianCalendar
(
tz
);
c
=
createGregorianCalendar
(
tz
);
CACHED_CALENDAR_NON_DEFAULT_TIMEZONE
.
set
(
c
);
}
c
.
clear
();
...
...
@@ -1201,19 +1200,19 @@ public class DateTimeUtils {
* @return timestamp with time zone
*/
public
static
ValueTimestampTimeZone
timestampTimeZoneFromLocalDateValueAndNanos
(
long
dateValue
,
long
timeNanos
)
{
int
timeZoneOffset
=
DateTimeUtils
.
getTimeZoneOffsetMillis
(
null
,
dateValue
,
timeNanos
);
int
timeZoneOffset
=
getTimeZoneOffsetMillis
(
null
,
dateValue
,
timeNanos
);
int
offsetMins
=
timeZoneOffset
/
60_000
;
int
correction
=
timeZoneOffset
%
60_000
;
if
(
correction
!=
0
)
{
timeNanos
-=
correction
;
if
(
timeNanos
<
0
)
{
timeNanos
+=
DateTimeUtils
.
NANOS_PER_DAY
;
timeNanos
+=
NANOS_PER_DAY
;
dateValue
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
-
1
);
}
else
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
timeNanos
-=
DateTimeUtils
.
NANOS_PER_DAY
;
.
dateValueFromAbsoluteDay
(
absoluteDayFromDateValue
(
dateValue
)
-
1
);
}
else
if
(
timeNanos
>=
NANOS_PER_DAY
)
{
timeNanos
-=
NANOS_PER_DAY
;
dateValue
=
DateTimeUtils
.
dateValueFromAbsoluteDay
(
DateTimeUtils
.
absoluteDayFromDateValue
(
dateValue
)
+
1
);
.
dateValueFromAbsoluteDay
(
absoluteDayFromDateValue
(
dateValue
)
+
1
);
}
}
return
ValueTimestampTimeZone
.
fromDateValueAndNanos
(
dateValue
,
timeNanos
,
(
short
)
offsetMins
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论