- added default time for timestamp in UI
- added environment variable to set current time
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import "mmaschedule-go/event"
|
||||
import "strconv"
|
||||
import "time"
|
||||
|
||||
templ TemplEventPage(e event.Event, upcoming []event.ListUpcomingEventsRow) {
|
||||
<html data-theme="night">
|
||||
@@ -208,7 +209,7 @@ templ TemplFighterCol(f *event.Fighter, right bool) {
|
||||
|
||||
templ TemplTimestamp(timestamp int64) {
|
||||
<span data-timestamp={ strconv.FormatInt(timestamp, 10) }>
|
||||
//{{ date|date:'D M j, g:i A T' }}
|
||||
{ time.Unix(timestamp, 0).Format(time.RFC1123) }
|
||||
</span>
|
||||
}
|
||||
|
||||
|
||||
+23
-2
@@ -2,9 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"mmaschedule-go/event"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -37,7 +40,7 @@ func StaticHandler(prefix string) (http.Handler, error) {
|
||||
}
|
||||
|
||||
func RouteIndex(w http.ResponseWriter, r *http.Request, q *event.Queries) {
|
||||
slug, err := q.GetUpcomingEvent(r.Context(), time.Now().Unix())
|
||||
slug, err := q.GetUpcomingEvent(r.Context(), EventTime())
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
@@ -59,7 +62,7 @@ func RouteEvent(w http.ResponseWriter, r *http.Request, q *event.Queries) {
|
||||
return
|
||||
}
|
||||
|
||||
upcoming, err := q.ListUpcomingEvents(r.Context(), time.Now().Unix())
|
||||
upcoming, err := q.ListUpcomingEvents(r.Context(), EventTime())
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
@@ -68,6 +71,24 @@ func RouteEvent(w http.ResponseWriter, r *http.Request, q *event.Queries) {
|
||||
TemplEventPage(event, upcoming).Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func EventTime() int64 {
|
||||
timestamp, err := EnvTime()
|
||||
if err != nil {
|
||||
t := time.Now()
|
||||
return t.Add(time.Duration(-6) * time.Hour).Unix()
|
||||
} else {
|
||||
return timestamp
|
||||
}
|
||||
}
|
||||
|
||||
func EnvTime() (int64, error) {
|
||||
timestr := os.Getenv("CURRENT_TIME")
|
||||
if len(timestr) == 0 {
|
||||
return 0, fmt.Errorf("Time env is empty.")
|
||||
}
|
||||
return strconv.ParseInt(timestr, 10, 64)
|
||||
}
|
||||
|
||||
type StateHandler func(w http.ResponseWriter, r *http.Request, q *event.Queries)
|
||||
|
||||
type ServerState struct {
|
||||
|
||||
Reference in New Issue
Block a user