mirror of
https://github.com/jimeh/go-midjourney.git
synced 2026-02-19 01:46:41 +00:00
35 lines
517 B
Go
35 lines
517 B
Go
package midjourney
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const TimeFormat = "2006-01-02 15:04:05.999999"
|
|
|
|
type Time struct {
|
|
time.Time
|
|
}
|
|
|
|
func (ct *Time) UnmarshalJSON(b []byte) (err error) {
|
|
s := strings.Trim(string(b), "\"")
|
|
if s == "null" {
|
|
ct.Time = time.Time{}
|
|
|
|
return
|
|
}
|
|
|
|
ct.Time, err = time.Parse(TimeFormat, s)
|
|
|
|
return
|
|
}
|
|
|
|
func (ct *Time) MarshalJSON() ([]byte, error) {
|
|
if ct.Time.IsZero() {
|
|
return []byte("null"), nil
|
|
}
|
|
|
|
return []byte(fmt.Sprintf("\"%s\"", ct.Time.Format(TimeFormat))), nil
|
|
}
|