add issue tasks.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package scalars
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/99designs/gqlgen/graphql"
|
||||
"io"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func MarshalDuration(d time.Duration) graphql.Marshaler {
|
||||
return graphql.WriterFunc(func(w io.Writer) {
|
||||
_, _ = w.Write([]byte(strconv.Itoa(int(d.Milliseconds()))))
|
||||
})
|
||||
}
|
||||
|
||||
func UnmarshalDuration(v interface{}) (time.Duration, error) {
|
||||
switch v := v.(type) {
|
||||
case string:
|
||||
return time.ParseDuration(v)
|
||||
case int:
|
||||
return time.Millisecond * time.Duration(v), nil
|
||||
case int64:
|
||||
return time.Millisecond * time.Duration(v), nil
|
||||
case float64:
|
||||
return time.Millisecond * time.Duration(v), nil
|
||||
default:
|
||||
return 0, fmt.Errorf("%T is not a bool", v)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user