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 9c62d0be62ad38a68e3855bb51394f128ca9825e..55cb39ff82a4882e92c8c6b08eacaeee211c9cd1 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 8260adbad0c120c619777609ab9f960a8f04e11f..eca3320e0c31be792667740120fda64ea74ddac8 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"); } }