diff --git a/commands.go b/commands.go index 480e74530e..d24607d7a2 100644 --- a/commands.go +++ b/commands.go @@ -449,7 +449,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri // for idx, field := range []string{ // /* NAME */ name, // /* ID */ img.Id, - // /* CREATED */ future.HumanDuration(time.Now().Sub(time.Unix(img.Created, 0))) + " ago", + // /* CREATED */ HumanDuration(time.Now().Sub(time.Unix(img.Created, 0))) + " ago", // /* PARENT */ img.Parent, // } { // if idx == 0 { @@ -499,7 +499,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string) /* ID */ container.Id, /* IMAGE */ container.Image, /* COMMAND */ command, - /* CREATED */ future.HumanDuration(time.Now().Sub(container.Created)) + " ago", + /* CREATED */ HumanDuration(time.Now().Sub(container.Created)) + " ago", /* STATUS */ container.State.String(), /* COMMENT */ "", } { diff --git a/future/future.go b/future/future.go index 21b0eee385..bd62b353e0 100644 --- a/future/future.go +++ b/future/future.go @@ -23,29 +23,6 @@ func ComputeId(content io.Reader) (string, error) { return fmt.Sprintf("%x", h.Sum(nil)[:8]), nil } -func HumanDuration(d time.Duration) string { - if seconds := int(d.Seconds()); seconds < 1 { - return "Less than a second" - } else if seconds < 60 { - return fmt.Sprintf("%d seconds", seconds) - } else if minutes := int(d.Minutes()); minutes == 1 { - return "About a minute" - } else if minutes < 60 { - return fmt.Sprintf("%d minutes", minutes) - } else if hours := int(d.Hours()); hours == 1 { - return "About an hour" - } else if hours < 48 { - return fmt.Sprintf("%d hours", hours) - } else if hours < 24*7*2 { - return fmt.Sprintf("%d days", hours/24) - } else if hours < 24*30*3 { - return fmt.Sprintf("%d weeks", hours/24/7) - } else if hours < 24*365*2 { - return fmt.Sprintf("%d months", hours/24/30) - } - return fmt.Sprintf("%d years", d.Hours()/24/365) -} - func randomBytes() io.Reader { return bytes.NewBuffer([]byte(fmt.Sprintf("%x", rand.Int()))) } diff --git a/state.go b/state.go index d2c53b83ce..f438ff8727 100644 --- a/state.go +++ b/state.go @@ -2,7 +2,6 @@ package docker import ( "fmt" - "github.com/dotcloud/docker/future" "sync" "time" ) @@ -20,7 +19,7 @@ type State struct { // String returns a human-readable description of the state func (s *State) String() string { if s.Running { - return fmt.Sprintf("Up %s", future.HumanDuration(time.Now().Sub(s.StartedAt))) + return fmt.Sprintf("Up %s", HumanDuration(time.Now().Sub(s.StartedAt))) } return fmt.Sprintf("Exit %d", s.ExitCode) } diff --git a/utils.go b/utils.go index 520073e3ab..9a409f6b59 100644 --- a/utils.go +++ b/utils.go @@ -3,13 +3,40 @@ package docker import ( "bytes" "container/list" + "fmt" "io" "os" "os/exec" "path/filepath" "sync" + "time" ) +// HumanDuration returns a human-readable approximation of a duration +// (eg. "About a minute", "4 hours ago", etc.) +func HumanDuration(d time.Duration) string { + if seconds := int(d.Seconds()); seconds < 1 { + return "Less than a second" + } else if seconds < 60 { + return fmt.Sprintf("%d seconds", seconds) + } else if minutes := int(d.Minutes()); minutes == 1 { + return "About a minute" + } else if minutes < 60 { + return fmt.Sprintf("%d minutes", minutes) + } else if hours := int(d.Hours()); hours == 1 { + return "About an hour" + } else if hours < 48 { + return fmt.Sprintf("%d hours", hours) + } else if hours < 24*7*2 { + return fmt.Sprintf("%d days", hours/24) + } else if hours < 24*30*3 { + return fmt.Sprintf("%d weeks", hours/24/7) + } else if hours < 24*365*2 { + return fmt.Sprintf("%d months", hours/24/30) + } + return fmt.Sprintf("%d years", d.Hours()/24/365) +} + func Trunc(s string, maxlen int) string { if len(s) <= maxlen { return s