diff options
Diffstat (limited to 'listWindow.go')
| -rw-r--r-- | listWindow.go | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/listWindow.go b/listWindow.go index 876aab0..7aba7d7 100644 --- a/listWindow.go +++ b/listWindow.go @@ -2,11 +2,14 @@ package main import ( + "fmt" "io/ioutil" "net/http" "os" "path/filepath" + "strconv" "strings" + "time" "go.wit.com/gui" "go.wit.com/log" @@ -53,7 +56,9 @@ func listWindow() { lw.Draw() box := lw.Box() group := box.NewGroup("list") - group.NewButton("blah", func() {}) + group.NewButton("make new go version list", func() { + dumpVersions() + }) var lines []string var curs *section @@ -230,3 +235,67 @@ func dumpURL(url string) []string { return strings.Split(string(bodyBytes), "\n") } + +func dumpVersions() { + f, _ := os.OpenFile("/tmp/go.wit.com.versions", os.O_WRONLY|os.O_CREATE, 0600) + defer f.Close() + for _, sec := range allsections { + for _, wrepo := range sec.witRepos { + r, ok := me.allrepos[wrepo.path.String()] + if ok { + _, out := r.status.RunCmd([]string{"git", "log", "-1", "--format=%at", r.lastTag.String()}) + out = strings.TrimSpace(out) + + // Convert the string to an integer + gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64) + if err != nil { + fmt.Println("Error converting timestamp:", err) + return + } + + // Parse the Unix timestamp into a time.Time object + gitTagDate := time.Unix(gitTagTimestampInt, 0) + + // Get the current time + currentTime := time.Now() + + // Calculate the duration between the git tag date and the current time + duration := currentTime.Sub(gitTagDate) + + // s := fmt.Sprint(duration) + // fmt.Println("Duration since the git tag date:", s) + + // fmt.Println("Default formatting:", duration.String()) + // fmt.Println("Custom formatting:", formatDuration(duration)) + log.Warn("found:", wrepo.path.String(), r.lastTag.String(), out, formatDuration(duration)) + fmt.Fprintln(f, wrepo.path.String(), r.lastTag.String(), out) + } + //wrepo.path.Show() + } + } +} + +func formatDuration(d time.Duration) string { + seconds := int(d.Seconds()) % 60 + minutes := int(d.Minutes()) % 60 + hours := int(d.Hours()) % 24 + days := int(d.Hours()) / 24 + + result := "" + if days > 0 { + result += fmt.Sprintf("%dd ", days) + return result + } + if hours > 0 { + result += fmt.Sprintf("%dh ", hours) + return result + } + if minutes > 0 { + result += fmt.Sprintf("%dm ", minutes) + return result + } + if seconds > 0 { + result += fmt.Sprintf("%ds", seconds) + } + return result +} |
