summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-24 12:45:32 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-24 12:45:32 +0200
commit6a281cd5d47a3fe54f28302b5a1d8a5171c841bd (patch)
treeb4429eff49963f80a7f3bb25ce0c4fc6c52db6e6
parent7847c071f9d588e30b17226dde4e93355c142d08 (diff)
Add PubDate parser
-rw-r--r--rss.go27
1 files changed, 25 insertions, 2 deletions
diff --git a/rss.go b/rss.go
index ecf6f24..eb553a6 100644
--- a/rss.go
+++ b/rss.go
@@ -4,6 +4,8 @@ package rss
import (
"encoding/xml"
"net/http"
+ "strings"
+ "time"
"code.google.com/p/go-charset/charset"
_ "code.google.com/p/go-charset/data"
@@ -15,13 +17,18 @@ type RSS struct {
Channel Channel `xml:"channel"`
}
+// Time in RFC1123Z or RFC1123 format
+type Time struct {
+ time.Time
+}
+
// Channel container
type Channel struct {
Link string `xml:"link"`
Language string `xml:"language"`
Title string `xml:"title"`
Description string `xml:"description"`
- PubDate string `xml:"pubDate"`
+ PubDate Time `xml:"pubDate"`
Items []Item `xml:"item"`
}
@@ -31,7 +38,23 @@ type Item struct {
Link string `xml:"link"`
GUID string `xml:"guid"`
Title string `xml:"title"`
- PubDate string `xml:"pubDate"`
+ PubDate Time `xml:"pubDate"`
+}
+
+// UnmarshalXML decodes Time format
+func (t *Time) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
+ var v string
+ d.DecodeElement(&v, &start)
+ v = strings.TrimSpace(v)
+ parse, err := time.Parse(time.RFC1123Z, v)
+ if err != nil {
+ parse, err = time.Parse(time.RFC1123, v)
+ if err != nil {
+ return err
+ }
+ }
+ *t = Time{parse}
+ return nil
}
// Fetch and parse RSS from given URL