Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
35bda43c
提交
35bda43c
authored
7 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move getTimeZone() to ToChar and change return values to suitable for this class
上级
c901b9cd
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
34 行删除
+40
-34
ToChar.java
h2/src/main/org/h2/util/ToChar.java
+40
-7
ValueTimestampTimeZone.java
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
+0
-27
没有找到文件。
h2/src/main/org/h2/util/ToChar.java
浏览文件 @
35bda43c
...
...
@@ -476,6 +476,44 @@ public class ToChar {
return
result
[
names
];
}
/**
* Returns time zone display name or ID for the specified date-time value.
*
* @param value
* value
* @param tzd
* if {@code true} return TZD (time zone region with Daylight Saving
* Time information included), if {@code false} return TZR (time zone
* region)
* @return time zone display name or ID
*/
private
static
String
getTimeZone
(
Value
value
,
boolean
tzd
)
{
if
(!(
value
instanceof
ValueTimestampTimeZone
))
{
TimeZone
tz
=
TimeZone
.
getDefault
();
if
(
tzd
)
{
boolean
daylight
=
tz
.
inDaylightTime
(
new
java
.
util
.
Date
());
return
tz
.
getDisplayName
(
daylight
,
TimeZone
.
SHORT
);
}
return
tz
.
getID
();
}
int
offset
=
((
ValueTimestampTimeZone
)
value
).
getTimeZoneOffsetMins
();
if
(
offset
==
0
)
{
return
"UTC"
;
}
StringBuilder
b
=
new
StringBuilder
(
9
);
b
.
append
(
"GMT"
);
if
(
offset
<
0
)
{
b
.
append
(
'-'
);
offset
=
-
offset
;
}
else
{
b
.
append
(
'+'
);
}
StringUtils
.
appendZeroPadded
(
b
,
2
,
offset
/
60
);
b
.
append
(
':'
);
StringUtils
.
appendZeroPadded
(
b
,
2
,
offset
%
60
);
return
b
.
toString
();
}
/**
* Emulates Oracle's TO_CHAR(datetime) function.
*
...
...
@@ -755,15 +793,10 @@ public class ToChar {
// Time zone
}
else
if
(
containsAt
(
format
,
i
,
"TZR"
)
!=
null
)
{
TimeZone
tz
=
value
instanceof
ValueTimestampTimeZone
?
((
ValueTimestampTimeZone
)
value
).
getTimeZone
()
:
TimeZone
.
getDefault
();
output
.
append
(
tz
.
getID
());
output
.
append
(
getTimeZone
(
value
,
false
));
i
+=
3
;
}
else
if
(
containsAt
(
format
,
i
,
"TZD"
)
!=
null
)
{
TimeZone
tz
=
value
instanceof
ValueTimestampTimeZone
?
((
ValueTimestampTimeZone
)
value
).
getTimeZone
()
:
TimeZone
.
getDefault
();
boolean
daylight
=
tz
.
inDaylightTime
(
new
java
.
util
.
Date
());
output
.
append
(
tz
.
getDisplayName
(
daylight
,
TimeZone
.
SHORT
));
output
.
append
(
getTimeZone
(
value
,
true
));
i
+=
3
;
// Week
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/value/ValueTimestampTimeZone.java
浏览文件 @
35bda43c
...
...
@@ -9,13 +9,10 @@ import java.math.BigDecimal;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.Timestamp
;
import
java.util.SimpleTimeZone
;
import
java.util.TimeZone
;
import
org.h2.api.ErrorCode
;
import
org.h2.api.TimestampWithTimeZone
;
import
org.h2.message.DbException
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.StringUtils
;
/**
* Implementation of the TIMESTAMP WITH TIME ZONE data type.
...
...
@@ -149,30 +146,6 @@ public class ValueTimestampTimeZone extends Value {
return
timeZoneOffsetMins
;
}
/**
* Returns compatible offset-based time zone with no DST schedule.
*
* @return compatible offset-based time zone
*/
public
TimeZone
getTimeZone
()
{
int
offset
=
timeZoneOffsetMins
;
if
(
offset
==
0
)
{
return
DateTimeUtils
.
UTC
;
}
StringBuilder
b
=
new
StringBuilder
(
9
);
b
.
append
(
"GMT"
);
if
(
offset
<
0
)
{
b
.
append
(
'-'
);
offset
=
-
offset
;
}
else
{
b
.
append
(
'+'
);
}
StringUtils
.
appendZeroPadded
(
b
,
2
,
offset
/
60
);
b
.
append
(
':'
);
StringUtils
.
appendZeroPadded
(
b
,
2
,
offset
%
60
);
return
new
SimpleTimeZone
(
offset
*
60000
,
b
.
toString
());
}
@Override
public
Timestamp
getTimestamp
()
{
throw
new
UnsupportedOperationException
(
"unimplemented"
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论