mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 15:55:14 +00:00
35 lines
479 B
Go
35 lines
479 B
Go
|
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
|
||
|
}
|