]> Cypherpunks repositories - gostls13.git/commitdiff
misc/dashboard/codereview: more abbreviated modification duration.
authorDavid Symonds <dsymonds@golang.org>
Fri, 27 Apr 2012 07:12:09 +0000 (17:12 +1000)
committerDavid Symonds <dsymonds@golang.org>
Fri, 27 Apr 2012 07:12:09 +0000 (17:12 +1000)
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/6131044

misc/dashboard/codereview/dashboard/cl.go
misc/dashboard/codereview/dashboard/front.go

index a023ff6ab84ccbdc2979721856c61b1ff56ffe71..e427176109fa6065b1a2dbeac82ae191f60a1483 100644 (file)
@@ -47,9 +47,9 @@ type CL struct {
        Reviewer string
 }
 
-// ShortOwner returns the CL's owner, either as their email address
+// DisplayOwner returns the CL's owner, either as their email address
 // or the person ID if it's a reviewer. It is for display only.
-func (cl *CL) ShortOwner() string {
+func (cl *CL) DisplayOwner() string {
        if p, ok := emailToPerson[cl.Owner]; ok {
                return p
        }
@@ -79,13 +79,20 @@ func (cl *CL) LGTMHTML() template.HTML {
 }
 
 func (cl *CL) ModifiedAgo() string {
+       // Just the first non-zero unit.
+       units := map[string]time.Duration{
+               "d": 24 * time.Hour,
+               "h": time.Hour,
+               "m": time.Minute,
+               "s": time.Second,
+       }
        d := time.Now().Sub(cl.Modified)
-       d -= d % time.Minute // truncate to minute resolution
-       s := d.String()
-       if strings.HasSuffix(s, "0s") {
-               s = s[:len(s)-2]
+       for suffix, u := range units {
+               if d > u {
+                       return fmt.Sprintf("%d%s", d/u, suffix)
+               }
        }
-       return s
+       return "just now"
 }
 
 func handleAssign(w http.ResponseWriter, r *http.Request) {
index efdfe2946702c65e22ed75dda2b3326988009341..a687e859668e9db39a9eef1e21d4bcdb419e8169 100644 (file)
@@ -192,7 +192,7 @@ var frontPage = template.Must(template.New("front").Funcs(template.FuncMap{
 <table class="cls">
 {{range $cl := .CLs}}
   <tr id="cl-{{$cl.Number}}">
-    <td class="email">{{$cl.ShortOwner}}</td>
+    <td class="email">{{$cl.DisplayOwner}}</td>
     {{if $tbl.Assignable}}
     <td>
     <select id="cl-rev-{{$cl.Number}}" {{if not $.UserIsReviewer}}disabled{{end}}>