diff --git a/print.go b/print.go index df65831a..405b3754 100644 --- a/print.go +++ b/print.go @@ -425,15 +425,21 @@ type Item struct { Creator string `xml:"dc:creator"` } -func (item Item) Print() error { +func (item Item) Print(installTime time.Time) { + var fd string date, err := time.Parse(time.RFC1123Z, item.PubDate) if err != nil { - return err + fmt.Println(err) + } else { + fd = formatTime(int(date.Unix())) + if _, double, _ := cmdArgs.getArg("news", "w"); !double && !installTime.IsZero() { + if installTime.After(date) { + return + } + } } - fd := formatTime(int(date.Unix())) - fmt.Println(bold(magenta(fd)), bold(strings.TrimSpace(item.Title))) //fmt.Println(strings.TrimSpace(item.Link)) @@ -442,7 +448,7 @@ func (item Item) Print() error { fmt.Println(desc) } - return nil + return } type Channel struct { @@ -478,19 +484,18 @@ func printNewsFeed() error { return err } + installTime, err := lastInstallTime() + if err != nil { + return err + } + if config.SortMode == BottomUp { for i := len(rss.Channel.Items) - 1; i >= 0; i-- { - err := rss.Channel.Items[i].Print() - if err != nil { - return err - } + rss.Channel.Items[i].Print(installTime) } } else { for i := 0; i < len(rss.Channel.Items); i++ { - err := rss.Channel.Items[i].Print() - if err != nil { - return err - } + rss.Channel.Items[i].Print(installTime) } } diff --git a/query.go b/query.go index 8e4c0a45..94ec1994 100644 --- a/query.go +++ b/query.go @@ -5,6 +5,7 @@ import ( "sort" "strings" "sync" + "time" alpm "github.com/jguer/go-alpm" rpc "github.com/mikkeloscar/aur" @@ -407,6 +408,26 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) { return } +func lastInstallTime() (time.Time, error) { + var time time.Time + + localDb, err := alpmHandle.LocalDb() + if err != nil { + return time, err + } + + localDb.PkgCache().ForEach(func(pkg alpm.Package) error { + thisTime := pkg.InstallDate() + if thisTime.After(time) { + time = thisTime + } + + return nil + }) + + return time, nil +} + // Statistics returns statistics about packages installed in system func statistics() (info struct { Totaln int