Browse code

Consolidate time format for API

Consolidate all the API to same time format: RFC3339, and it will be
client's responsibility to present it in more user friendly way.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>

Zhang Wei authored on 2015/11/30 23:44:06
Showing 4 changed files
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"runtime"
6 6
 	"text/template"
7
+	"time"
7 8
 
8 9
 	"github.com/docker/docker/api"
9 10
 	"github.com/docker/docker/api/types"
... ...
@@ -72,6 +73,16 @@ func (cli *DockerCli) CmdVersion(args ...string) (err error) {
72 72
 	}
73 73
 
74 74
 	defer func() {
75
+		// first we need to make BuildTime more human friendly
76
+		t, errTime := time.Parse(time.RFC3339Nano, vd.Client.BuildTime)
77
+		if errTime == nil {
78
+			vd.Client.BuildTime = t.Format(time.ANSIC)
79
+		}
80
+		t, errTime = time.Parse(time.RFC3339Nano, vd.Server.BuildTime)
81
+		if errTime == nil {
82
+			vd.Server.BuildTime = t.Format(time.ANSIC)
83
+		}
84
+
75 85
 		if err2 := tmpl.Execute(cli.out, vd); err2 != nil && err == nil {
76 86
 			err = err2
77 87
 		}
... ...
@@ -99,6 +99,8 @@ This section lists each version from latest to oldest.  Each listing includes a
99 99
 * `GET /info` Now returns `Architecture` and `OSType` fields, providing information
100 100
   about the host architecture and operating system type that the daemon runs on.
101 101
 * `GET /networks/(name)` now returns a `Name` field for each container attached to the network.
102
+* `GET /version` now returns the `BuildTime` field in RFC3339Nano format to make it 
103
+  consistent with other date/time values returned by the API.
102 104
 
103 105
 ### v1.21 API changes
104 106
 
... ...
@@ -1990,14 +1990,15 @@ Show the docker version information
1990 1990
     Content-Type: application/json
1991 1991
 
1992 1992
     {
1993
-         "Version": "1.5.0",
1993
+         "Version": "1.10.0-dev",
1994 1994
          "Os": "linux",
1995
-         "KernelVersion": "3.18.5-tinycore64",
1996
-         "GoVersion": "go1.4.1",
1997
-         "GitCommit": "a8a31ef",
1995
+         "KernelVersion": "3.19.0-23-generic",
1996
+         "GoVersion": "go1.4.2",
1997
+         "GitCommit": "e75da4b",
1998 1998
          "Arch": "amd64",
1999
-         "ApiVersion": "1.20",
2000
-         "Experimental": false
1999
+         "ApiVersion": "1.22",
2000
+         "BuildTime": "2015-12-01T07:09:13.444803460+00:00",
2001
+         "Experimental": true
2001 2002
     }
2002 2003
 
2003 2004
 Status Codes:
... ...
@@ -70,7 +70,7 @@ if command -v git &> /dev/null && git rev-parse &> /dev/null; then
70 70
 	if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
71 71
 		GITCOMMIT="$GITCOMMIT-dirty"
72 72
 	fi
73
-	BUILDTIME=$(date -u)
73
+	BUILDTIME=$(date --rfc-3339 ns | sed -e 's/ /T/')
74 74
 elif [ "$DOCKER_GITCOMMIT" ]; then
75 75
 	GITCOMMIT="$DOCKER_GITCOMMIT"
76 76
 else