-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.go
More file actions
34 lines (28 loc) · 728 Bytes
/
Copy pathdate.go
File metadata and controls
34 lines (28 loc) · 728 Bytes
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
package sitemap
import (
"encoding/xml"
"time"
)
const (
shortFormat string = "2006-01-02"
fullFormat string = "2006-01-02T15:04:05-07:00"
)
// customDate is a time.Time value with custom XML unmarshal method.
type customDate struct {
time.Time
format string
}
// MarshalXML is a customer marshal method for customDate.
func (c *customDate) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
t := time.Time(c.Time)
v := t.Format(c.format)
return e.EncodeElement(v, start)
}
// Date returns a new short format date.
func Date(t time.Time) customDate {
return customDate{t, shortFormat}
}
// DateFull returns a long format date.
func DateFull(t time.Time) customDate {
return customDate{t, fullFormat}
}