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:
parent
525d2bdc03
commit
ee66dbdb55
12
feed.go
12
feed.go
|
@ -98,7 +98,7 @@ type Feed struct {
|
||||||
|
|
||||||
// Last time content was fetched. Used in conjunction with CacheTimeout
|
// Last time content was fetched. Used in conjunction with CacheTimeout
|
||||||
// to ensure we don't get content too often.
|
// to ensure we don't get content too often.
|
||||||
lastupdate int64
|
lastupdate time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// New is a helper function to stay semi-compatible with
|
// 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.
|
// This returns a timestamp of the last time the feed was updated.
|
||||||
// The value is in seconds.
|
func (this *Feed) LastUpdate() time.Time {
|
||||||
func (this *Feed) LastUpdate() int64 { return this.lastupdate }
|
return this.lastupdate
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch retrieves the feed's latest content if necessary.
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastupdate = time.Now().UTC().UnixNano()
|
this.lastupdate = time.Now().UTC()
|
||||||
this.Url = uri
|
this.Url = uri
|
||||||
doc := xmlx.New()
|
doc := xmlx.New()
|
||||||
|
|
||||||
|
@ -259,7 +260,8 @@ func (this *Feed) CanUpdate() bool {
|
||||||
// before the feed should update.
|
// before the feed should update.
|
||||||
func (this *Feed) SecondsTillUpdate() int64 {
|
func (this *Feed) SecondsTillUpdate() int64 {
|
||||||
utc := time.Now().UTC()
|
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) {
|
func (this *Feed) buildFeed(doc *xmlx.Document) (err error) {
|
||||||
|
|
Loading…
Reference in New Issue