summaryrefslogtreecommitdiff
path: root/gitTag.byAge.go
blob: eacf7578f5e57c21de745c3bda290bd4d6d5b6b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gitpb

// runs git, parses output
// types faster than you can

import (
	"sort"
	"time"
)

func (all *GitTags) SortByAge() *GitTagIterator {
	packs := all.selectAllGitTag()

	sort.Sort(GitTagAge(packs))

	iterator := NewGitTagIterator(packs)
	return iterator
}

type GitTagAge []*GitTag

func (a GitTagAge) Len() int { return len(a) }

// sorts in ? order
func (a GitTagAge) Less(i, j int) bool {
	if time.Since(a[i].Authordate.AsTime()) < time.Since(a[j].Authordate.AsTime()) {
		return true
	}
	return false
}
func (a GitTagAge) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func (repo *Repo) NewestAge() time.Duration {
	return time.Since(repo.Times.NewestCommit.AsTime())
	/*
		all := repo.Tags.SortByAge()
		for all.Scan() {
			r := all.Next()
			return time.Since(r.GetAuthordate().AsTime())
		}
		return time.Since(time.Now())
	*/
}