fix(type): 修复时间戳类型初始化问题

- 将 parseTimestamp 函数替换为 strconv.ParseInt,以正确解析时间戳
- 使用 ErrInvalidTimestamp 替换错误返回,提供更准确的错误信息
This commit is contained in:
gouguoyin
2025-09-16 11:08:43 +08:00
parent dfa61e7c06
commit 86876fcd6d
2 changed files with 4 additions and 2 deletions

View File

@@ -90,8 +90,8 @@ func (t *TimestampType[T]) UnmarshalJSON(src []byte) error {
ts int64
err error
)
if ts, err = parseTimestamp(v); err != nil {
return err
if ts, err = strconv.ParseInt(v, 10, 64); err != nil {
return ErrInvalidTimestamp(v)
}
var c *Carbon
switch t.getPrecision() {

View File

@@ -149,6 +149,8 @@ func (s *CarbonTypeSuite) TestCarbonType_UnmarshalJSON() {
s.Empty(model.Carbon1.String())
s.Empty(model.Carbon2.String())
s.False(model.Carbon1.IsValid())
s.False(model.Carbon2.IsValid())
})
s.Run("null value", func() {