mirror of https://github.com/docker/cli.git
Add CreatedAtTimestamp and fix CreatedAt docs
Signed-off-by: Simon H <simon9ha@gmail.com>
This commit is contained in:
parent
cfe18f5e03
commit
bd36415cbe
|
@ -192,11 +192,16 @@ func (c *ContainerContext) Command() string {
|
||||||
return strconv.Quote(command)
|
return strconv.Quote(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreatedAt returns the "Created" date/time of the container as a unix timestamp.
|
// CreatedAt returns the "Created" date/time of the container as a string
|
||||||
func (c *ContainerContext) CreatedAt() string {
|
func (c *ContainerContext) CreatedAt() string {
|
||||||
return time.Unix(c.c.Created, 0).String()
|
return time.Unix(c.c.Created, 0).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatedAtTimestamp returns the "Created" date/time of the container as a unix timestamp
|
||||||
|
func (c *ContainerContext) CreatedAtTimestamp() time.Time {
|
||||||
|
return time.Unix(c.c.Created, 0)
|
||||||
|
}
|
||||||
|
|
||||||
// RunningFor returns a human-readable representation of the duration for which
|
// RunningFor returns a human-readable representation of the duration for which
|
||||||
// the container has been running.
|
// the container has been running.
|
||||||
//
|
//
|
||||||
|
|
|
@ -336,16 +336,19 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContainerContextWriteJSON(t *testing.T) {
|
func TestContainerContextWriteJSON(t *testing.T) {
|
||||||
unix := time.Now().Add(-65 * time.Second).Unix()
|
ts := time.Now().Add(-65 * time.Second)
|
||||||
|
unix := ts.Unix()
|
||||||
containers := []types.Container{
|
containers := []types.Container{
|
||||||
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix, State: "running"},
|
{ID: "containerID1", Names: []string{"/foobar_baz"}, Image: "ubuntu", Created: unix, State: "running"},
|
||||||
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix, State: "running"},
|
{ID: "containerID2", Names: []string{"/foobar_bar"}, Image: "ubuntu", Created: unix, State: "running"},
|
||||||
}
|
}
|
||||||
expectedCreated := time.Unix(unix, 0).String()
|
expectedCreated := time.Unix(unix, 0).String()
|
||||||
|
expectedCreatedAtTimestamp := ts.Format(time.RFC3339)
|
||||||
expectedJSONs := []map[string]any{
|
expectedJSONs := []map[string]any{
|
||||||
{
|
{
|
||||||
"Command": "\"\"",
|
"Command": "\"\"",
|
||||||
"CreatedAt": expectedCreated,
|
"CreatedAt": expectedCreated,
|
||||||
|
"CreatedAtTimestamp": expectedCreatedAtTimestamp,
|
||||||
"ID": "containerID1",
|
"ID": "containerID1",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Labels": "",
|
"Labels": "",
|
||||||
|
@ -362,6 +365,7 @@ func TestContainerContextWriteJSON(t *testing.T) {
|
||||||
{
|
{
|
||||||
"Command": "\"\"",
|
"Command": "\"\"",
|
||||||
"CreatedAt": expectedCreated,
|
"CreatedAt": expectedCreated,
|
||||||
|
"CreatedAtTimestamp": expectedCreatedAtTimestamp,
|
||||||
"ID": "containerID2",
|
"ID": "containerID2",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Labels": "",
|
"Labels": "",
|
||||||
|
|
Loading…
Reference in New Issue