diff --git a/pkg/schema/field/timestamp.go b/pkg/schema/field/timestamp.go index a96899542709d4cbab72978dce6dbf7e566d86b7..cc13bbea2dc0b657e20157a0bed3c9640b64ce0b 100644 --- a/pkg/schema/field/timestamp.go +++ b/pkg/schema/field/timestamp.go @@ -30,28 +30,10 @@ func (TimestampType) IsEmpty(v interface{}) bool { return v == 0 || v == nil } -func (TimestampType) Decode(_ context.Context, _ *Field, v interface{}) (interface{}, error) { - switch i := v.(type) { - case nil: - return nil, nil - case string: - duration, err := time.ParseDuration(i) - if err == nil { - return duration.Nanoseconds(), nil - } - t, err := time.Parse(time.TimeOnly, i) - - if err == nil { - return t.AddDate(1, 0, 0).Sub(zeroTime).Nanoseconds(), nil - } - return nil, err - default: - return toTimestamp(i) - } -} - func toTimestamp(i interface{}) (interface{}, error) { switch v := i.(type) { + case nil: + return nil, nil case int64: return v, nil case int: @@ -69,14 +51,30 @@ func toTimestamp(i interface{}) (interface{}, error) { case uint32: return int64(v), nil default: - return 0, fmt.Errorf("unsupported value type: \"%T\"", v) + return 0, fmt.Errorf("unsupported value type: \"%T\"", i) + } +} + +func (TimestampType) Decode(_ context.Context, _ *Field, v interface{}) (interface{}, error) { + switch i := v.(type) { + case string: + duration, err := time.ParseDuration(i) + if err == nil { + return duration.Nanoseconds(), nil + } + t, err := time.Parse(time.TimeOnly, i) + + if err == nil { + return t.AddDate(1, 0, 0).Sub(zeroTime).Nanoseconds(), nil + } + return nil, err + default: + return toTimestamp(i) } } func (TimestampType) Encode(_ context.Context, _ *Field, v interface{}) (interface{}, error) { switch i := v.(type) { - case nil: - return nil, nil default: return toTimestamp(i) }