1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #15010 from runcom/14947-fix-inspect-time-RFC3339Nano

Format times in inspect command with a template as RFC3339Nano
This commit is contained in:
David Calavera 2015-07-27 10:08:21 -07:00
commit e89aec0dfb
4 changed files with 36 additions and 8 deletions

View file

@ -86,7 +86,7 @@ type ImageInspect struct {
Id string Id string
Parent string Parent string
Comment string Comment string
Created time.Time Created string
Container string Container string
ContainerConfig *runconfig.Config ContainerConfig *runconfig.Config
DockerVersion string DockerVersion string
@ -215,14 +215,14 @@ type ContainerState struct {
Pid int Pid int
ExitCode int ExitCode int
Error string Error string
StartedAt time.Time StartedAt string
FinishedAt time.Time FinishedAt string
} }
// GET "/containers/{name:.*}/json" // GET "/containers/{name:.*}/json"
type ContainerJSONBase struct { type ContainerJSONBase struct {
Id string Id string
Created time.Time Created string
Path string Path string
Args []string Args []string
State *ContainerState State *ContainerState

View file

@ -2,6 +2,7 @@ package daemon
import ( import (
"fmt" "fmt"
"time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
) )
@ -91,13 +92,13 @@ func (daemon *Daemon) getInspectData(container *Container) (*types.ContainerJSON
Pid: container.State.Pid, Pid: container.State.Pid,
ExitCode: container.State.ExitCode, ExitCode: container.State.ExitCode,
Error: container.State.Error, Error: container.State.Error,
StartedAt: container.State.StartedAt, StartedAt: container.State.StartedAt.Format(time.RFC3339Nano),
FinishedAt: container.State.FinishedAt, FinishedAt: container.State.FinishedAt.Format(time.RFC3339Nano),
} }
contJSONBase := &types.ContainerJSONBase{ contJSONBase := &types.ContainerJSONBase{
Id: container.ID, Id: container.ID,
Created: container.Created, Created: container.Created.Format(time.RFC3339Nano),
Path: container.Path, Path: container.Path,
Args: container.Args, Args: container.Args,
State: containerState, State: containerState,

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"io" "io"
"runtime" "runtime"
"time"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
@ -34,7 +35,7 @@ func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
Id: image.ID, Id: image.ID,
Parent: image.Parent, Parent: image.Parent,
Comment: image.Comment, Comment: image.Comment,
Created: image.Created, Created: image.Created.Format(time.RFC3339Nano),
Container: image.Container, Container: image.Container,
ContainerConfig: &image.ContainerConfig, ContainerConfig: &image.ContainerConfig,
DockerVersion: image.DockerVersion, DockerVersion: image.DockerVersion,

View file

@ -5,6 +5,7 @@ import (
"os/exec" "os/exec"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/go-check/check" "github.com/go-check/check"
@ -260,3 +261,28 @@ func (s *DockerSuite) TestInspectBindMountPoint(c *check.C) {
c.Fatalf("Expected rw to be false") c.Fatalf("Expected rw to be false")
} }
} }
// #14947
func (s *DockerSuite) TestInspectTimesAsRFC3339Nano(c *check.C) {
out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
id := strings.TrimSpace(out)
startedAt, err := inspectField(id, "State.StartedAt")
c.Assert(err, check.IsNil)
finishedAt, err := inspectField(id, "State.FinishedAt")
c.Assert(err, check.IsNil)
created, err := inspectField(id, "Created")
c.Assert(err, check.IsNil)
_, err = time.Parse(time.RFC3339Nano, startedAt)
c.Assert(err, check.IsNil)
_, err = time.Parse(time.RFC3339Nano, finishedAt)
c.Assert(err, check.IsNil)
_, err = time.Parse(time.RFC3339Nano, created)
c.Assert(err, check.IsNil)
created, err = inspectField("busybox", "Created")
c.Assert(err, check.IsNil)
_, err = time.Parse(time.RFC3339Nano, created)
c.Assert(err, check.IsNil)
}