Time parsing.

Rather than just using a string for PubDate, we attempt to parse it.
This includes a couple of crazy non-standard time formats that I've seen
in the wild.

Breaking change: Item.PubDate is no longer a string, it is time.Time.
This commit is contained in:
Sean Schulte 2014-03-24 21:54:15 -05:00
parent 2b6dc03ede
commit 2c67b94a04
5 changed files with 135 additions and 5 deletions

View file

@ -3,6 +3,7 @@ package feeder
import (
"crypto/md5"
"io"
"time"
)
type Item struct {
@ -15,7 +16,7 @@ type Item struct {
Comments string
Enclosures []*Enclosure
Guid *string
PubDate string
PubDate time.Time
Source *Source
// Atom specific fields
@ -33,8 +34,8 @@ func (i *Item) Key() string {
return *i.Guid
case len(i.Id) != 0:
return i.Id
case len(i.Title) > 0 && len(i.PubDate) > 0:
return i.Title + i.PubDate
case len(i.Title) > 0 && !i.PubDate.IsZero():
return i.Title + i.PubDate.String()
default:
h := md5.New()
io.WriteString(h, i.Description)