Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
d6545417
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d6545417
编写于
11月 05, 2009
作者:
K
Keith Donald
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
iso date time format tests
上级
8de34c6f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
4 deletion
+70
-4
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java
...framework/format/datetime/joda/JodaTimeContextHolder.java
+1
-1
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormattingConfigurer.java
...rk/format/datetime/joda/JodaTimeFormattingConfigurer.java
+1
-0
org.springframework.context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
...amework/format/datetime/joda/JodaTimeFormattingTests.java
+66
-1
org.springframework.context/src/test/java/org/springframework/mapping/support/MappingTests.java
...ava/org/springframework/mapping/support/MappingTests.java
+2
-2
未找到文件。
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeContextHolder.java
浏览文件 @
d6545417
...
@@ -42,7 +42,7 @@ public final class JodaTimeContextHolder {
...
@@ -42,7 +42,7 @@ public final class JodaTimeContextHolder {
* @param context the current JodaTimeContext, or <code>null</code> to clear
* @param context the current JodaTimeContext, or <code>null</code> to clear
* the thread-bound context
* the thread-bound context
*/
*/
public
static
void
set
Local
eContext
(
JodaTimeContext
context
)
{
public
static
void
set
JodaTim
eContext
(
JodaTimeContext
context
)
{
jodaTimeContextHolder
.
set
(
context
);
jodaTimeContextHolder
.
set
(
context
);
}
}
...
...
org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormattingConfigurer.java
浏览文件 @
d6545417
...
@@ -103,6 +103,7 @@ public class JodaTimeFormattingConfigurer {
...
@@ -103,6 +103,7 @@ public class JodaTimeFormattingConfigurer {
formatterRegistry
.
addFormatterForFieldType
(
Date
.
class
,
new
MillisecondInstantPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldType
(
Date
.
class
,
new
MillisecondInstantPrinter
(
jodaDateTimeFormatter
),
dateTimeParser
);
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
DateTimeFormatAnnotationFormatterFactory
());
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
DateTimeFormatAnnotationFormatterFactory
());
formatterRegistry
.
addFormatterForFieldAnnotation
(
new
ISODateTimeFormatAnnotationFormatterFactory
());
}
}
// internal helpers
// internal helpers
...
...
org.springframework.context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
浏览文件 @
d6545417
...
@@ -7,6 +7,7 @@ import java.util.Date;
...
@@ -7,6 +7,7 @@ import java.util.Date;
import
java.util.Locale
;
import
java.util.Locale
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTime
;
import
org.joda.time.DateTimeZone
;
import
org.joda.time.LocalDate
;
import
org.joda.time.LocalDate
;
import
org.joda.time.LocalDateTime
;
import
org.joda.time.LocalDateTime
;
import
org.joda.time.LocalTime
;
import
org.joda.time.LocalTime
;
...
@@ -16,6 +17,7 @@ import org.junit.Test;
...
@@ -16,6 +17,7 @@ import org.junit.Test;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.beans.MutablePropertyValues
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.context.i18n.LocaleContextHolder
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
org.springframework.format.annotation.ISODateTimeFormat
;
import
org.springframework.format.annotation.DateTimeFormat.Style
;
import
org.springframework.format.annotation.DateTimeFormat.Style
;
import
org.springframework.format.datetime.joda.JodaTimeFormattingConfigurer
;
import
org.springframework.format.datetime.joda.JodaTimeFormattingConfigurer
;
import
org.springframework.format.support.FormattingConversionService
;
import
org.springframework.format.support.FormattingConversionService
;
...
@@ -36,11 +38,15 @@ public class JodaTimeFormattingTests {
...
@@ -36,11 +38,15 @@ public class JodaTimeFormattingTests {
binder
.
setConversionService
(
conversionService
);
binder
.
setConversionService
(
conversionService
);
LocaleContextHolder
.
setLocale
(
Locale
.
US
);
LocaleContextHolder
.
setLocale
(
Locale
.
US
);
JodaTimeContext
context
=
new
JodaTimeContext
();
context
.
setTimeZone
(
DateTimeZone
.
forID
(
"-05:00"
));
JodaTimeContextHolder
.
setJodaTimeContext
(
context
);
}
}
@After
@After
public
void
tearDown
()
{
public
void
tearDown
()
{
LocaleContextHolder
.
setLocale
(
null
);
LocaleContextHolder
.
setLocale
(
null
);
JodaTimeContextHolder
.
setJodaTimeContext
(
null
);
}
}
@Test
@Test
...
@@ -120,7 +126,6 @@ public class JodaTimeFormattingTests {
...
@@ -120,7 +126,6 @@ public class JodaTimeFormattingTests {
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"dateTimeAnnotated"
,
"Oct 31, 2009 12:00 PM"
);
propertyValues
.
addPropertyValue
(
"dateTimeAnnotated"
,
"Oct 31, 2009 12:00 PM"
);
binder
.
bind
(
propertyValues
);
binder
.
bind
(
propertyValues
);
System
.
out
.
println
(
binder
.
getBindingResult
());
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotated"
));
assertEquals
(
"Oct 31, 2009 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotated"
));
}
}
...
@@ -179,6 +184,33 @@ public class JodaTimeFormattingTests {
...
@@ -179,6 +184,33 @@ public class JodaTimeFormattingTests {
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"millisAnnotated"
));
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"millisAnnotated"
));
}
}
@Test
public
void
testBindISODate
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"isoDate"
,
"2009-10-31"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"2009-10-31"
,
binder
.
getBindingResult
().
getFieldValue
(
"isoDate"
));
}
@Test
public
void
testBindISOTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"isoTime"
,
"12:00:00.000-05:00"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"12:00:00.000"
,
binder
.
getBindingResult
().
getFieldValue
(
"isoTime"
));
}
@Test
public
void
testBindISODateTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
addPropertyValue
(
"isoDateTime"
,
"2009-10-31T12:00:00.000Z"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"2009-10-31T07:00:00.000-05:00"
,
binder
.
getBindingResult
().
getFieldValue
(
"isoDateTime"
));
}
public
static
class
JodaTimeBean
{
public
static
class
JodaTimeBean
{
private
LocalDate
localDate
;
private
LocalDate
localDate
;
...
@@ -216,6 +248,15 @@ public class JodaTimeFormattingTests {
...
@@ -216,6 +248,15 @@ public class JodaTimeFormattingTests {
@DateTimeFormat
(
dateStyle
=
Style
.
SHORT
)
@DateTimeFormat
(
dateStyle
=
Style
.
SHORT
)
private
Long
millisAnnotated
;
private
Long
millisAnnotated
;
@ISODateTimeFormat
(
org
.
springframework
.
format
.
annotation
.
ISODateTimeFormat
.
Style
.
DATE
)
private
LocalDate
isoDate
;
@ISODateTimeFormat
(
org
.
springframework
.
format
.
annotation
.
ISODateTimeFormat
.
Style
.
TIME
)
private
LocalTime
isoTime
;
@ISODateTimeFormat
(
org
.
springframework
.
format
.
annotation
.
ISODateTimeFormat
.
Style
.
DATE_TIME
)
private
DateTime
isoDateTime
;
public
LocalDate
getLocalDate
()
{
public
LocalDate
getLocalDate
()
{
return
localDate
;
return
localDate
;
}
}
...
@@ -328,5 +369,29 @@ public class JodaTimeFormattingTests {
...
@@ -328,5 +369,29 @@ public class JodaTimeFormattingTests {
this
.
millisAnnotated
=
millisAnnotated
;
this
.
millisAnnotated
=
millisAnnotated
;
}
}
public
LocalDate
getIsoDate
()
{
return
isoDate
;
}
public
void
setIsoDate
(
LocalDate
isoDate
)
{
this
.
isoDate
=
isoDate
;
}
public
LocalTime
getIsoTime
()
{
return
isoTime
;
}
public
void
setIsoTime
(
LocalTime
isoTime
)
{
this
.
isoTime
=
isoTime
;
}
public
DateTime
getIsoDateTime
()
{
return
isoDateTime
;
}
public
void
setIsoDateTime
(
DateTime
isoDateTime
)
{
this
.
isoDateTime
=
isoDateTime
;
}
}
}
}
}
org.springframework.context/src/test/java/org/springframework/mapping/support/MappingTests.java
浏览文件 @
d6545417
...
@@ -326,7 +326,7 @@ public class MappingTests {
...
@@ -326,7 +326,7 @@ public class MappingTests {
// field to multiple fields
// field to multiple fields
.
addAssemblerMapping
(
"activationDateTime"
,
new
Converter
<
Map
<
String
,
String
>,
DateTime
>()
{
.
addAssemblerMapping
(
"activationDateTime"
,
new
Converter
<
Map
<
String
,
String
>,
DateTime
>()
{
public
DateTime
convert
(
Map
<
String
,
String
>
source
)
{
public
DateTime
convert
(
Map
<
String
,
String
>
source
)
{
MutableDateTime
dateTime
=
new
MutableDateTime
(
DateTimeZone
.
forID
(
"-0
4
:00"
));
MutableDateTime
dateTime
=
new
MutableDateTime
(
DateTimeZone
.
forID
(
"-0
5
:00"
));
dateTime
.
setYear
(
Integer
.
parseInt
(
source
.
get
(
"year"
)));
dateTime
.
setYear
(
Integer
.
parseInt
(
source
.
get
(
"year"
)));
dateTime
.
setMonthOfYear
(
Integer
.
parseInt
(
source
.
get
(
"month"
)));
dateTime
.
setMonthOfYear
(
Integer
.
parseInt
(
source
.
get
(
"month"
)));
dateTime
.
setDayOfMonth
(
Integer
.
parseInt
(
source
.
get
(
"day"
)));
dateTime
.
setDayOfMonth
(
Integer
.
parseInt
(
source
.
get
(
"day"
)));
...
@@ -344,7 +344,7 @@ public class MappingTests {
...
@@ -344,7 +344,7 @@ public class MappingTests {
source
.
put
(
"activationDateTime.hour"
,
"12"
);
source
.
put
(
"activationDateTime.hour"
,
"12"
);
source
.
put
(
"activationDateTime.minute"
,
"0"
);
source
.
put
(
"activationDateTime.minute"
,
"0"
);
Account
account
=
mapper
.
map
(
source
,
new
Account
());
Account
account
=
mapper
.
map
(
source
,
new
Account
());
assertEquals
(
ISODateTimeFormat
.
dateTime
().
withOffsetParsed
().
parseDateTime
(
"2009-10-12T12:00:00.000-0
4
:00"
),
account
assertEquals
(
ISODateTimeFormat
.
dateTime
().
withOffsetParsed
().
parseDateTime
(
"2009-10-12T12:00:00.000-0
5
:00"
),
account
.
getActivationDateTime
());
.
getActivationDateTime
());
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录