Merge pull request #3122 from zhibo6/master

修复问题:当时间为1970-01-01 08:00:00 时,TypeUtils.castToTimestamp 转换异常。
This commit is contained in:
温绍锦
2020-04-30 20:58:07 +08:00
committed by GitHub
2 changed files with 7 additions and 1 deletions
@@ -707,7 +707,8 @@ public class TypeUtils{
}
}
}
if(longValue <= 0){
if(longValue < 0){
throw new JSONException("can not cast to Timestamp, value : " + value);
}
return new java.sql.Timestamp(longValue);
@@ -3,6 +3,7 @@ package com.alibaba.json.bvt.parser;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -243,6 +244,10 @@ public class TypeUtilsTest extends TestCase {
Assert.assertEquals(null, TypeUtils.castToTimestamp(null));
}
public void test_cast_to_Timestamp_1970_01_01_00_00_00() throws Exception {
Assert.assertEquals(new Timestamp(0), TypeUtils.castToTimestamp("1970-01-01 08:00:00"));
}
public void test_cast_to_BigDecimal_same() throws Exception {
BigDecimal value = new BigDecimal("123");
Assert.assertEquals(true, value == TypeUtils.castToBigDecimal(value));