Store time of last update as time.Time

This commit breaks the API, because LastUpdate() now returns a
time.Time object instead of an int64.
This commit is contained in:
Michael K 2014-11-28 16:53:09 +01:00
parent 525d2bdc03
commit ee66dbdb55
1 changed files with 7 additions and 5 deletions

12
feed.go
View File

@ -98,7 +98,7 @@ type Feed struct {
// Last time content was fetched. Used in conjunction with CacheTimeout
// to ensure we don't get content too often.
lastupdate int64
lastupdate time.Time
}
// New is a helper function to stay semi-compatible with
@ -125,8 +125,9 @@ func NewWithHandlers(cachetimeout int, enforcecachelimit bool, ch ChannelHandler
}
// This returns a timestamp of the last time the feed was updated.
// The value is in seconds.
func (this *Feed) LastUpdate() int64 { return this.lastupdate }
func (this *Feed) LastUpdate() time.Time {
return this.lastupdate
}
// Fetch retrieves the feed's latest content if necessary.
//
@ -154,7 +155,7 @@ func (this *Feed) FetchClient(uri string, client *http.Client, charset xmlx.Char
return
}
this.lastupdate = time.Now().UTC().UnixNano()
this.lastupdate = time.Now().UTC()
this.Url = uri
doc := xmlx.New()
@ -259,7 +260,8 @@ func (this *Feed) CanUpdate() bool {
// before the feed should update.
func (this *Feed) SecondsTillUpdate() int64 {
utc := time.Now().UTC()
return int64(this.CacheTimeout*60) - (utc.Unix() - (this.lastupdate / 1e9))
elapsed := utc.Sub(this.lastupdate)
return int64(this.CacheTimeout*60) - int64(elapsed.Seconds())
}
func (this *Feed) buildFeed(doc *xmlx.Document) (err error) {