Skip to content

Commit

Permalink
Merge branch 'release/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
axllent committed Apr 9, 2020
2 parents 2d34b56 + 7fcbc33 commit 8e293a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.0.2]

- Show duration estimate for weeks, months and years


## [0.0.1]

- First release
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {

// set the default help
flag.Usage = func() {
fmt.Printf("Wireguard Vanity Key Generator (%s)\n\n", appVersion)
fmt.Printf("WireGuard Vanity Key Generator (%s)\n\n", appVersion)
// fmt.Printf("Version: %s\n\n", appVersion)
fmt.Printf("Usage: %s [OPTIONS] <SEARCH> [<SEARCH>...]\n\n", os.Args[0])
fmt.Println("Options:")
Expand Down
17 changes: 17 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ func isValidSearch(s string) bool {

// Returns a human-readable output of time.Duration
func humanizeDuration(duration time.Duration) string {
// more than duration can handle
if duration.Hours() < 0.0 {
return fmt.Sprintf("hundreds of years")
}
if duration.Hours() > 8760.0 {
y := int64(duration.Hours() / 8760)
return fmt.Sprintf("%d %s", y, plural("year", y))
}
if duration.Hours() > 720.0 {
m := int64(duration.Hours() / 24 / 30)
return fmt.Sprintf("%d %s", m, plural("month", m))
}
if duration.Hours() > 168.0 {
w := int64(duration.Hours() / 168)
return fmt.Sprintf("%d %s", w, plural("week", w))
}
if duration.Seconds() < 60.0 {
s := int64(duration.Seconds())
return fmt.Sprintf("%d %s", s, plural("second", s))
Expand All @@ -30,6 +46,7 @@ func humanizeDuration(duration time.Duration) string {
return fmt.Sprintf("%d %s, %d %s",
h, plural("hour", h), m, plural("minute", m))
}
// if duration.Hours() <
h := int64(math.Mod(duration.Hours(), 24))
d := int64(duration.Hours() / 24)
return fmt.Sprintf("%d %s, %d %s",
Expand Down

0 comments on commit 8e293a1

Please sign in to comment.