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 { ...@@ -30,28 +30,10 @@ func (TimestampType) IsEmpty(v interface{}) bool {
return v == 0 || v == nil 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) { func toTimestamp(i interface{}) (interface{}, error) {
switch v := i.(type) { switch v := i.(type) {
case nil:
return nil, nil
case int64: case int64:
return v, nil return v, nil
case int: case int:
...@@ -69,14 +51,30 @@ func toTimestamp(i interface{}) (interface{}, error) { ...@@ -69,14 +51,30 @@ func toTimestamp(i interface{}) (interface{}, error) {
case uint32: case uint32:
return int64(v), nil return int64(v), nil
default: 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) { func (TimestampType) Encode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
switch i := v.(type) { switch i := v.(type) {
case nil:
return nil, nil
default: default:
return toTimestamp(i) 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