summaryrefslogtreecommitdiff
path: root/unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'unix.go')
-rw-r--r--unix.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/unix.go b/unix.go
index 1126a1b..0b2df4b 100644
--- a/unix.go
+++ b/unix.go
@@ -2,14 +2,17 @@ package repostatus
import (
"errors"
+ "fmt"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
+ "strconv"
"strings"
"syscall"
+ "time"
"go.wit.com/log"
)
@@ -264,3 +267,57 @@ func readFileToString(filename string) (string, error) {
}
return strings.TrimSpace(string(data)), nil
}
+
+func getDateStamp(raw string) (string, string) {
+ parts := strings.Split(raw, " ")
+ if len(parts) == 0 {
+ // raw was blank here
+ return "Jan 4 1977", "40y" // eh, why not. it'll be easy to grep for this
+ }
+ i, err := strconv.ParseInt(parts[0], 10, 64) // base 10 string, return int64
+ if err != nil {
+ log.Warn("Error converting timestamp:", raw)
+ log.Warn("Error converting timestamp err =", err)
+ return raw, ""
+ }
+
+ // Parse the Unix timestamp into a time.Time object
+ gitTagDate := time.Unix(i, 0)
+ return gitTagDate.UTC().Format("2006/01/02 15:04:05 UTC"), getDurationStamp(gitTagDate)
+}
+
+func getDurationStamp(t time.Time) string {
+
+ // Get the current time
+ currentTime := time.Now()
+
+ // Calculate the duration between t current time
+ duration := currentTime.Sub(t)
+
+ return formatDuration(duration)
+}
+
+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
+}