Skip to content

Commit

Permalink
Use native build date when printing news
Browse files Browse the repository at this point in the history
Use the build date of the newest native package instead of the install
date of any package.
  • Loading branch information
Morganamilo committed May 17, 2018
1 parent 6be6ffc commit d6ab6ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ type Item struct {
Creator string `xml:"dc:creator"`
}

func (item Item) Print(installTime time.Time) {
func (item Item) Print(buildTime time.Time) {
var fd string
date, err := time.Parse(time.RFC1123Z, item.PubDate)

if err != nil {
fmt.Println(err)
} else {
fd = formatTime(int(date.Unix()))
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !installTime.IsZero() {
if installTime.After(date) {
if _, double, _ := cmdArgs.getArg("news", "w"); !double && !buildTime.IsZero() {
if buildTime.After(date) {
return
}
}
Expand Down Expand Up @@ -484,18 +484,18 @@ func printNewsFeed() error {
return err
}

installTime, err := lastInstallTime()
buildTime, err := lastBuildTime()
if err != nil {
return err
}

if config.SortMode == BottomUp {
for i := len(rss.Channel.Items) - 1; i >= 0; i-- {
rss.Channel.Items[i].Print(installTime)
rss.Channel.Items[i].Print(buildTime)
}
} else {
for i := 0; i < len(rss.Channel.Items); i++ {
rss.Channel.Items[i].Print(installTime)
rss.Channel.Items[i].Print(buildTime)
}
}

Expand Down
12 changes: 5 additions & 7 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,20 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) {
return
}

func lastInstallTime() (time.Time, error) {
func lastBuildTime() (time.Time, error) {
var time time.Time

localDb, err := alpmHandle.LocalDb()
pkgs, _, _, _, err := filterPackages()
if err != nil {
return time, err
}

localDb.PkgCache().ForEach(func(pkg alpm.Package) error {
thisTime := pkg.InstallDate()
for _, pkg := range pkgs {
thisTime := pkg.BuildDate()
if thisTime.After(time) {
time = thisTime
}

return nil
})
}

return time, nil
}
Expand Down

0 comments on commit d6ab6ed

Please sign in to comment.