bbgo_origin/pkg/datasource/wise/time.go

35 lines
479 B
Go
Raw Normal View History

2023-11-11 02:16:55 +00:00
package wise
import (
"encoding/json"
"time"
)
const layout = "2006-01-02T15:04:05-0700"
type Time time.Time
func (t Time) Time() time.Time {
return time.Time(t)
}
func (t Time) String() string {
return time.Time(t).Format(layout)
}
func (t *Time) UnmarshalJSON(data []byte) error {
var s string
err := json.Unmarshal(data, &s)
if err != nil {
return err
}
parsed, err := time.Parse(layout, s)
if err != nil {
return err
}
*t = Time(parsed)
return nil
}