-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
35 lines (30 loc) · 673 Bytes
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package vgmdb
import (
"strconv"
"time"
)
const (
dtwsLayout = "2006-01-02T15:04"
)
// DateTimeWithoutSeconds represents a date (year, month, day) and time (hour, minute).
type DateTimeWithoutSeconds struct {
time.Time
}
func (d *DateTimeWithoutSeconds) MarshalJSON() ([]byte, error) {
if d.Time.IsZero() {
return []byte("null"), nil
}
return []byte(strconv.Quote(d.Time.Format(dtwsLayout))), nil
}
func (d *DateTimeWithoutSeconds) UnmarshalJSON(data []byte) error {
s, err := strconv.Unquote(string(data))
if err != nil {
s = string(data)
}
if s == "null" {
d.Time = time.Time{}
return nil
}
d.Time, err = time.Parse(dtwsLayout, s)
return err
}