-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mingard/feat/date-format
Add date format
- Loading branch information
Showing
6 changed files
with
104 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters