Print times in human-readable format

main
Jasper Bok 2023-08-13 15:01:17 +02:00
parent c2ad110b7b
commit aa958b77b1
3 changed files with 10 additions and 3 deletions

2
TODO
View File

@ -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).

View File

@ -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>

View File

@ -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)