Print times in human-readable format
parent
c2ad110b7b
commit
aa958b77b1
2
TODO
2
TODO
|
@ -2,7 +2,7 @@
|
|||
|
||||
## 1.0.0
|
||||
|
||||
[ ] *.. Print times in human-readable format.
|
||||
[x] *.. Print times in human-readable format.
|
||||
[ ] *.. Show max two departures per line per stop.
|
||||
[ ] **. Add Connexxion departures.
|
||||
[ ] **. Make the page look nice (also on mobile).
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
{{ range .Departures }}
|
||||
<dl>
|
||||
<dt>{{ .RouteShortName }} | {{ .StopHeadsign }}</dt>
|
||||
<dd><time>{{ .DepartureTime }}</time></dd>
|
||||
<dd><time>{{ formatTime .DepartureTime }}</time></dd>
|
||||
</dl>
|
||||
{{ end }}
|
||||
</article>
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TemplateQuay struct {
|
||||
|
@ -16,6 +17,12 @@ type TemplateContext struct {
|
|||
Quays []TemplateQuay
|
||||
}
|
||||
|
||||
func formatTime(t time.Time) string {
|
||||
return t.Format("15:04")
|
||||
}
|
||||
|
||||
var tplFunctions = template.FuncMap{"formatTime": formatTime}
|
||||
|
||||
func serveHttp() {
|
||||
http.HandleFunc("/", handleIndex)
|
||||
|
||||
|
@ -40,7 +47,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {
|
|||
ctxt.Quays = append(ctxt.Quays, TemplateQuay{quay.Name, quay.Town, departures})
|
||||
}
|
||||
|
||||
tpl := template.New("index.html")
|
||||
tpl := template.New("index.html").Funcs(tplFunctions)
|
||||
tpl, _ = tpl.ParseFiles("index.html")
|
||||
|
||||
_ = tpl.Execute(w, ctxt)
|
||||
|
|
Loading…
Reference in New Issue