Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #127 from nats-io/humanize_2
Browse files Browse the repository at this point in the history
further human friendly formatting
  • Loading branch information
ripienaar authored Mar 23, 2020
2 parents d62148e + 7b2c8cf commit bab1a6e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/nats-io/jetstream
go 1.12

require (
github.com/AlecAivazis/survey/v2 v2.0.5
github.com/AlecAivazis/survey/v2 v2.0.7
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/dustin/go-humanize v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/AlecAivazis/survey/v2 v2.0.5 h1:xpZp+Q55wi5C7Iaze+40onHnEkex1jSc34CltJjOoPM=
github.com/AlecAivazis/survey/v2 v2.0.5/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/AlecAivazis/survey/v2 v2.0.7 h1:+f825XHLse/hWd2tE/V5df04WFGimk34Eyg/z35w/rc=
github.com/AlecAivazis/survey/v2 v2.0.7/go.mod h1:mlizQTaPjnR4jcpwRSaSlkbsRfYFEyKgLQvYTzxxiHA=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
Expand Down
2 changes: 1 addition & 1 deletion nats/consumer_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (c *consumerCmd) infoAction(pc *kingpin.ParseContext) error {
if config.StreamSeq != 0 {
fmt.Printf(" Start Sequence: %d\n", config.StreamSeq)
}
if !config.StartTime.IsZero() {
if config.StartTime.Second() != 0 {
fmt.Printf(" Start Time: %v\n", config.StartTime)
}
if config.DeliverAll {
Expand Down
2 changes: 1 addition & 1 deletion nats/stream_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (c *streamCmd) showStreamConfig(cfg api.StreamConfig) {
if cfg.MaxAge == -1 {
fmt.Println(" Maximum Age: unlimited")
} else {
fmt.Printf(" Maximum Age: %s\n", cfg.MaxAge.String())
fmt.Printf(" Maximum Age: %s\n", humanizeDuration(cfg.MaxAge))
}
if cfg.MaxMsgSize == -1 {
fmt.Println(" Maximum Message Size: unlimited")
Expand Down
8 changes: 5 additions & 3 deletions nats/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ func prepareHelper(servers string, opts ...nats.Option) (*nats.Conn, error) {
return nc, err
}

func humanizeTime(t time.Time) string {
d := time.Since(t)
// Just use total seconds for uptime, and display days / years
func humanizeDuration(d time.Duration) string {
tsecs := d / time.Second
tmins := tsecs / 60
thrs := tmins / 60
Expand All @@ -348,3 +346,7 @@ func humanizeTime(t time.Time) string {

return fmt.Sprintf("%ds", tsecs)
}

func humanizeTime(t time.Time) string {
return humanizeDuration(time.Since(t))
}

0 comments on commit bab1a6e

Please sign in to comment.