diff --git a/.golangci.yml b/.golangci.yml index c5b3a7d..102361f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -29,7 +29,6 @@ linters: - github.com/lestrrat-go/apache-logformat - github.com/ncruces/zenity - github.com/energye/systray - - github.com/dromara/carbon/v2 - github.com/mitchellh/go-homedir - github.com/fsnotify/fsnotify - github.com/radovskyb/watcher diff --git a/go.mod b/go.mod index e6a1817..65bb04d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.26.4 require ( code.cloudfoundry.org/bytefmt v0.76.0 github.com/BurntSushi/toml v1.6.0 - github.com/dromara/carbon/v2 v2.6.16 github.com/energye/systray v1.0.3 github.com/fsnotify/fsnotify v1.10.1 github.com/julienschmidt/httprouter v1.3.0 diff --git a/go.sum b/go.sum index 78baae0..82761d7 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dchest/jsmin v1.0.0 h1:Y2hWXmGZiRxtl+VcTksyucgTlYxnhPzTozCwx9gy9zI= github.com/dchest/jsmin v1.0.0/go.mod h1:AVBIund7Mr7lKXT70hKT2YgL3XEXUaUk5iw9DZ8b0Uc= -github.com/dromara/carbon/v2 v2.6.16 h1:AbxrnW1kJhR3KHdS8G96NFmxDwPFyre+t+xSiJIUD1I= -github.com/dromara/carbon/v2 v2.6.16/go.mod h1:NGo3reeV5vhWCYWcSqbJRZm46MEwyfYI5EJRdVFoLJo= github.com/dsnet/compress v0.0.1 h1:PlZu0n3Tuv04TzpfPbrnI0HW/YwodEXDS+oPKahKF0Q= github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo= github.com/energye/systray v1.0.3 h1:XnyjJCeRU5z00bpNOic2fGTKz/7yHZMZjWiGIVXDS+4= diff --git a/pkg/unpackerr/cnfgfile.go b/pkg/unpackerr/cnfgfile.go index 8ab7b71..ca2523b 100644 --- a/pkg/unpackerr/cnfgfile.go +++ b/pkg/unpackerr/cnfgfile.go @@ -9,10 +9,10 @@ import ( "runtime" "strconv" "strings" + "time" "github.com/Unpackerr/unpackerr/examples" "github.com/Unpackerr/unpackerr/pkg/ui" - "github.com/dromara/carbon/v2" homedir "github.com/mitchellh/go-homedir" "golift.io/cnfg" "golift.io/cnfgfile" @@ -77,7 +77,7 @@ func (f *Flags) ConfigFileWithAge() string { return f.ConfigFile + ", unknown age" } - age := carbon.CreateFromStdTime(stat.ModTime()).DiffAbsInString() + age := formatDuration(time.Since(stat.ModTime())) return f.ConfigFile + ", age: " + age } diff --git a/pkg/unpackerr/duration.go b/pkg/unpackerr/duration.go new file mode 100644 index 0000000..f9b57b8 --- /dev/null +++ b/pkg/unpackerr/duration.go @@ -0,0 +1,62 @@ +package unpackerr + +import ( + "strconv" + "strings" + "time" +) + +const ( + durationPartsLimit = 3 + daysPerWeek = 7 + daysPerYear = 365 + hoursPerDay = 24 +) + +func formatDuration(duration time.Duration) string { + duration = duration.Abs() + units := []struct { + name string + duration time.Duration + }{ + {name: "year", duration: daysPerYear * hoursPerDay * time.Hour}, + {name: "week", duration: daysPerWeek * hoursPerDay * time.Hour}, + {name: "day", duration: hoursPerDay * time.Hour}, + {name: "hour", duration: time.Hour}, + {name: "minute", duration: time.Minute}, + {name: "second", duration: time.Second}, + {name: "millisecond", duration: time.Millisecond}, + {name: "microsecond", duration: time.Microsecond}, + } + + parts := make([]string, 0, durationPartsLimit) + remaining := duration + + for _, unit := range units { + count := int64(remaining / unit.duration) + if count == 0 { + continue + } + + parts = append(parts, formatDurationPart(count, unit.name)) + remaining -= time.Duration(count) * unit.duration + + if len(parts) == durationPartsLimit { + break + } + } + + if len(parts) == 0 { + return "0 seconds" + } + + return strings.Join(parts, " ") +} + +func formatDurationPart(count int64, name string) string { + if count == 1 { + return strconv.FormatInt(count, 10) + " " + name + } + + return strconv.FormatInt(count, 10) + " " + name + "s" +} diff --git a/pkg/unpackerr/logs.go b/pkg/unpackerr/logs.go index c7b97a1..8e9f6d1 100644 --- a/pkg/unpackerr/logs.go +++ b/pkg/unpackerr/logs.go @@ -11,7 +11,6 @@ import ( "time" "github.com/Unpackerr/unpackerr/pkg/ui" - "github.com/dromara/carbon/v2" homedir "github.com/mitchellh/go-homedir" "golift.io/rotatorr" "golift.io/rotatorr/timerotator" @@ -126,7 +125,7 @@ func (u *Unpackerr) logCurrentQueue(now time.Time) { " %d|%d cmdhooks, stacks; event:%d, hook:%d, del:%d, up %s", u.Retries, u.Finished, stats.HookOK, stats.HookFail, stats.CmdOK, stats.CmdFail, len(u.folders.Events)+len(u.updates)+len(u.folders.Updates), len(u.hookChan), len(u.delChan), - carbon.CreateFromStdTime(version.Started).DiffAbsInString(carbon.CreateFromStdTime(now))) + formatDuration(now.Sub(version.Started))) u.updateTray(stats, uint(len(u.folders.Events)+len(u.updates)+len(u.folders.Updates)+len(u.delChan)+len(u.hookChan))) } diff --git a/pkg/unpackerr/tray.go b/pkg/unpackerr/tray.go index 8a74f72..b8241a0 100644 --- a/pkg/unpackerr/tray.go +++ b/pkg/unpackerr/tray.go @@ -8,11 +8,11 @@ import ( "os/signal" "strconv" "syscall" + "time" "github.com/Unpackerr/unpackerr/pkg/bindata" "github.com/Unpackerr/unpackerr/pkg/ui" "github.com/Unpackerr/unpackerr/pkg/update" - "github.com/dromara/carbon/v2" "github.com/energye/systray" "golift.io/version" ) @@ -230,7 +230,7 @@ func (u *Unpackerr) checkForUpdate() { return } - ago := carbon.CreateFromStdTime(update.RelDate).DiffAbsInString() + ago := formatDuration(time.Since(update.RelDate)) if !update.Outdate { _, _ = ui.Info("Unpackerr", "You're up to date! Version: %s\nUpdated: %s (%s ago)",