Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
91b2048d
提交
91b2048d
authored
9月 24, 2016
作者:
Noel Grandin
提交者:
GitHub
9月 24, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #361 from marschall/timestamp-with-time-zone-javadoc
Improve TimestampWithTimeZone javadoc
上级
ddaa9950
411d6a15
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
73 行增加
和
0 行删除
+73
-0
TimestampWithTimeZone.java
h2/src/main/org/h2/api/TimestampWithTimeZone.java
+37
-0
TestTimeStampWithTimeZone.java
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
+36
-0
没有找到文件。
h2/src/main/org/h2/api/TimestampWithTimeZone.java
浏览文件 @
91b2048d
...
@@ -46,18 +46,55 @@ public class TimestampWithTimeZone implements Serializable, Cloneable {
...
@@ -46,18 +46,55 @@ public class TimestampWithTimeZone implements Serializable, Cloneable {
return
dateValue
;
return
dateValue
;
}
}
/**
* Gets the year.
*
* <p>The year is in the specified time zone and not UTC. So for
* {@code 2015-12-31 19:00:00.00-10:00} the value returned
* will be {@code 2015} even though in UTC the year is {@code 2016}.</p>
*
* @return the year
*/
public
int
getYear
()
{
public
int
getYear
()
{
return
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
return
DateTimeUtils
.
yearFromDateValue
(
dateValue
);
}
}
/**
* Gets the month 1-based.
*
* <p>The month is in the specified time zone and not UTC. So for
* {@code 2015-12-31 19:00:00.00-10:00} the value returned
* is {@code 12} even though in UTC the month is {@code 1}.</p>
*
* @return the month
*/
public
int
getMonth
()
{
public
int
getMonth
()
{
return
DateTimeUtils
.
monthFromDateValue
(
dateValue
);
return
DateTimeUtils
.
monthFromDateValue
(
dateValue
);
}
}
/**
* Gets the day of month 1-based.
*
* <p>The day of month is in the specified time zone and not UTC. So for
* {@code 2015-12-31 19:00:00.00-10:00} the value returned
* is {@code 31} even though in UTC the day of month is {@code 1}.</p>
*
* @return the day of month
*/
public
int
getDay
()
{
public
int
getDay
()
{
return
DateTimeUtils
.
dayFromDateValue
(
dateValue
);
return
DateTimeUtils
.
dayFromDateValue
(
dateValue
);
}
}
/**
* Gets the nanoseconds since midnight.
*
* <p>The nanoseconds are relative to midnight in the specified
* time zone. So for {@code 2016-09-24 00:00:00.000000001-00:01} the
* value returned is {@code 1} even though {@code 60000000001}
* nanoseconds have passed since midnight in UTC.</p>
*
* @return the nanoseconds since midnight
*/
public
long
getNanosSinceMidnight
()
{
public
long
getNanosSinceMidnight
()
{
return
timeNanos
;
return
timeNanos
;
}
}
...
...
h2/src/test/org/h2/test/unit/TestTimeStampWithTimeZone.java
浏览文件 @
91b2048d
...
@@ -37,11 +37,47 @@ public class TestTimeStampWithTimeZone extends TestBase {
...
@@ -37,11 +37,47 @@ public class TestTimeStampWithTimeZone extends TestBase {
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id identity, t1 timestamp with timezone)"
);
stat
.
execute
(
"create table test(id identity, t1 timestamp with timezone)"
);
stat
.
execute
(
"insert into test(t1) values('1970-01-01 12:00:00.00+00:15')"
);
stat
.
execute
(
"insert into test(t1) values('1970-01-01 12:00:00.00+00:15')"
);
// verify NanosSinceMidnight is in local time and not UTC
stat
.
execute
(
"insert into test(t1) values('2016-09-24 00:00:00.000000001+00:01')"
);
stat
.
execute
(
"insert into test(t1) values('2016-09-24 00:00:00.000000001-00:01')"
);
// verify year month day is in local time and not UTC
stat
.
execute
(
"insert into test(t1) values('2016-01-01 05:00:00.00+10:00')"
);
stat
.
execute
(
"insert into test(t1) values('2015-12-31 19:00:00.00-10:00')"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test"
);
ResultSet
rs
=
stat
.
executeQuery
(
"select t1 from test"
);
rs
.
next
();
rs
.
next
();
assertEquals
(
"1970-01-01 12:00:00.0+00:15"
,
rs
.
getString
(
1
));
assertEquals
(
"1970-01-01 12:00:00.0+00:15"
,
rs
.
getString
(
1
));
TimestampWithTimeZone
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
TimestampWithTimeZone
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
assertEquals
(
1970
,
ts
.
getYear
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getDay
());
assertEquals
(
15
,
ts
.
getTimeZoneOffsetMins
());
assertEquals
(
new
TimestampWithTimeZone
(
1008673L
,
43200000000000L
,
(
short
)
15
),
ts
);
assertEquals
(
new
TimestampWithTimeZone
(
1008673L
,
43200000000000L
,
(
short
)
15
),
ts
);
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
24
,
ts
.
getDay
());
assertEquals
(
1
,
ts
.
getTimeZoneOffsetMins
());
assertEquals
(
1L
,
ts
.
getNanosSinceMidnight
());
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
9
,
ts
.
getMonth
());
assertEquals
(
24
,
ts
.
getDay
());
assertEquals
(-
1
,
ts
.
getTimeZoneOffsetMins
());
assertEquals
(
1L
,
ts
.
getNanosSinceMidnight
());
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
assertEquals
(
2016
,
ts
.
getYear
());
assertEquals
(
1
,
ts
.
getMonth
());
assertEquals
(
1
,
ts
.
getDay
());
rs
.
next
();
ts
=
(
TimestampWithTimeZone
)
rs
.
getObject
(
1
);
assertEquals
(
2015
,
ts
.
getYear
());
assertEquals
(
12
,
ts
.
getMonth
());
assertEquals
(
31
,
ts
.
getDay
());
rs
.
close
();
stat
.
close
();
conn
.
close
();
conn
.
close
();
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论