1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 22:24:51 +02:00

use reflogs from state to work out branch recencies

This commit is contained in:
Jesse Duffield
2020-03-26 22:51:24 +11:00
parent bd2c1eef53
commit fbbd16bd82
7 changed files with 64 additions and 75 deletions

21
pkg/utils/date.go Normal file
View File

@@ -0,0 +1,21 @@
package utils
import (
"fmt"
"time"
)
func UnixToTimeAgo(timestamp int) string {
now := time.Now().Unix()
delta := float64(now - int64(timestamp))
// we go seconds, minutes, hours, days, weeks, months, years
conversions := []float64{60, 60, 24, 7, 4.34524, 12}
labels := []string{"s", "m", "h", "d", "w", "m", "y"}
for i, conversion := range conversions {
if delta < conversion {
return fmt.Sprintf("%d%s", int(delta), labels[i])
}
delta /= conversion
}
return fmt.Sprintf("%dy", int(delta))
}