Skip to content
Snippets Groups Projects
Commit 9d6af0a4 authored by ko_oler's avatar ko_oler
Browse files

правки по ПР

parent 926329d7
No related branches found
No related tags found
No related merge requests found
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment