From 4fdb8adb663a42d4123fb0b88b32d7cfd403744a Mon Sep 17 00:00:00 2001 From: Golden Shaw Date: Mon, 22 Sep 2014 08:55:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BE=8B=E5=AD=90=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/org/dayatang/domain/DataType.java | 10 +++++----- .../dayatang/domain/datatype/DataTypeTest.java | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/dddlib-domain/src/main/java/org/dayatang/domain/DataType.java b/dddlib-domain/src/main/java/org/dayatang/domain/DataType.java index 9c62d0be6..55cb39ff8 100644 --- a/dddlib-domain/src/main/java/org/dayatang/domain/DataType.java +++ b/dddlib-domain/src/main/java/org/dayatang/domain/DataType.java @@ -1,11 +1,11 @@ package org.dayatang.domain; -import org.apache.commons.lang3.time.DateUtils; - import java.math.BigDecimal; import java.text.ParseException; import java.util.Date; + import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; /** * 数据类型枚举。 @@ -63,7 +63,7 @@ public enum DataType { @Override public Date getValue(String value) { try { - return StringUtils.isBlank(value) ? null : DateUtils.parseDate(value, TIME_FORMAT); + return StringUtils.isBlank(value) ? null : DateUtils.parseDateStrictly(value, TIME_FORMAT); } catch (ParseException e) { throw new IllegalArgumentException("'" + value + "' cannot be converted to Time" + e); } @@ -87,6 +87,6 @@ public enum DataType { */ public abstract Object getValue(String value); protected static final String DATE_FORMAT = "yyyy-MM-dd"; - protected static final String TIME_FORMAT = "hh:mm:ss"; - protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd hh:mm:ss"; + protected static final String TIME_FORMAT = "HH:mm:ss"; + protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; } diff --git a/dddlib-domain/src/test/java/org/dayatang/domain/datatype/DataTypeTest.java b/dddlib-domain/src/test/java/org/dayatang/domain/datatype/DataTypeTest.java index 8260adbad..eca3320e0 100644 --- a/dddlib-domain/src/test/java/org/dayatang/domain/datatype/DataTypeTest.java +++ b/dddlib-domain/src/test/java/org/dayatang/domain/datatype/DataTypeTest.java @@ -1,15 +1,16 @@ package org.dayatang.domain.datatype; +import java.math.BigDecimal; +import java.text.ParseException; + import org.apache.commons.lang3.time.DateUtils; +import org.dayatang.domain.DataType; import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.math.BigDecimal; -import java.text.ParseException; -import org.dayatang.domain.DataType; - -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class DataTypeTest { @@ -61,11 +62,11 @@ public class DataTypeTest { @Test(expected = IllegalArgumentException.class) public void testTimeException() { - DataType.DATE.getValue("28:70:88"); + DataType.TIME.getValue("28:70:88"); } @Test(expected = IllegalArgumentException.class) public void testDateTimeException() { - DataType.DATE.getValue("xxy-02-30 00:34:11"); + DataType.DATE_TIME.getValue("xxy-02-30 00:34:11"); } } -- Gitee