Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/cnfgfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
62 changes: 62 additions & 0 deletions pkg/unpackerr/duration.go
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 1 addition & 2 deletions pkg/unpackerr/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/unpackerr/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)",
Expand Down