Commits

Miki Tebeka committed 2dc9599

Format time

  • Participants
  • Parent commits bc3970a

Comments (0)

Files changed (2)

                 <td title="{{ .Long | html }}">
                     <a href="{{ .Long }}">{{ .Short }}</a>
                 </td>
-				<!-- FIXME: format -->
-                <td>{{ .Created }}</td>
+                <td>{{ .Created | strftime }}</td>
                 <td>{{ .Hits }}</td>
             </tr>
             {{ end }}

shortie/shortie.go

 var homeTemplate *template.Template
 
 func init() {
-	homeTemplate = template.Must(template.New("home").Parse(homeHTML))
+	var fmap = template.FuncMap {
+		"strftime" : timeFormatter,
+	}
+	homeTemplate = template.Must(template.New("home").Funcs(fmap).Parse(homeHTML))
 	http.HandleFunc("/", rootHandler)
 }
 
 	incHits(ctx, path)
 	http.Redirect(w, r, url.Long, http.StatusTemporaryRedirect)
 }
+
+func timeFormatter(args ...interface{}) string {
+	dt, ok := args[0].(datastore.Time)
+	if !ok {
+		return "ERR"
+	}
+	t := time.NanosecondsToLocalTime(int64(dt))
+	return t.Format("2006-01-02 15:04")
+}