Skip to content

Commit

Permalink
remove gox/timex dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
pete911 committed Jan 3, 2025
1 parent 290f752 commit 97b8760
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 435 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/pete911/certinfo
go 1.23

require (
github.com/icza/gox v0.2.0
github.com/stretchr/testify v1.10.0
golang.design/x/clipboard v0.7.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/icza/gox v0.2.0 h1:+0N8PCt9/QSx+k0dqe/wdlXJNR/haaPsPwrTJTNDeyk=
github.com/icza/gox v0.2.0/go.mod h1:rVecw5Q6POJAWBcXgCZdAtwK/hmoNehxCkAP3sMnOIc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
Expand Down
52 changes: 50 additions & 2 deletions pkg/print/expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package print

import (
"fmt"
"github.com/icza/gox/timex"
"github.com/pete911/certinfo/pkg/cert"
"time"
)
Expand Down Expand Up @@ -40,7 +39,7 @@ func expiryString(certificate cert.Certificate) string {

func formatExpiry(t time.Time) string {

year, month, day, hour, minute, _ := timex.Diff(time.Now(), t)
year, month, day, hour, minute, _ := timeDiff(time.Now(), t)
if year != 0 {
return fmt.Sprintf("%d years %d months %d days %d hours %d minutes", year, month, day, hour, minute)
}
Expand All @@ -55,3 +54,52 @@ func formatExpiry(t time.Time) string {
}
return fmt.Sprintf("%d minutes", minute)
}

// copied from github.com/icza/gox/timex Diff function
func timeDiff(a, b time.Time) (year, month, day, hour, min, sec int) {

if a.Location() != b.Location() {
b = b.In(a.Location())
}
if a.After(b) {
a, b = b, a
}
y1, M1, d1 := a.Date()
y2, M2, d2 := b.Date()

h1, m1, s1 := a.Clock()
h2, m2, s2 := b.Clock()

year = y2 - y1
month = int(M2 - M1)
day = d2 - d1
hour = h2 - h1
min = m2 - m1
sec = s2 - s1

// Normalize negative values
if sec < 0 {
sec += 60
min--
}
if min < 0 {
min += 60
hour--
}
if hour < 0 {
hour += 24
day--
}
if day < 0 {
// days in month:
t := time.Date(y1, M1, 32, 0, 0, 0, 0, time.UTC)
day += 32 - t.Day()
month--
}
if month < 0 {
month += 12
year--
}

return
}
201 changes: 0 additions & 201 deletions vendor/github.com/icza/gox/LICENSE

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/icza/gox/timex/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions vendor/github.com/icza/gox/timex/doc.go

This file was deleted.

60 changes: 0 additions & 60 deletions vendor/github.com/icza/gox/timex/duration.go

This file was deleted.

Loading

0 comments on commit 97b8760

Please sign in to comment.