Skip to content

Commit

Permalink
Show time distance for recently uploaded version
Browse files Browse the repository at this point in the history
  • Loading branch information
rykov committed Dec 16, 2021
1 parent 92addd2 commit 01c74ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions cli/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cli

import (
"fmt"
"regexp"
"time"
)

var (
roundDurationRE = regexp.MustCompile(`^\d+\w`)
)

func timeStringWithAgo(t time.Time) string {
out := t.Local().Format("2006-01-02 15:04")

if ago := time.Now().Sub(t); ago < 24*time.Hour {
if str := roundDurationRE.FindString(ago.String()); str != "" {
out = fmt.Sprintf("%s (~ %s ago)", out, str)
}
}

return out
}
2 changes: 1 addition & 1 deletion cli/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func listVersions(cmd *cobra.Command, args []string) error {
fmt.Fprintf(w, "version\tuploaded_by\tuploaded_at\n")

for _, v := range versions {
uploadedAt := v.CreatedAt.Local().Format("2006-01-02 15:04")
uploadedAt := timeStringWithAgo(v.CreatedAt)
fmt.Fprintf(w, "%s\t%s\t%s\n", v.Version, v.DisplayCreatedBy(), uploadedAt)
}

Expand Down

0 comments on commit 01c74ea

Please sign in to comment.