diff --git a/api.go b/api.go index 5608db7..65a3462 100644 --- a/api.go +++ b/api.go @@ -5,7 +5,9 @@ import ( "sort" "github.com/WeatherGod3218/counters/database" + "github.com/WeatherGod3218/counters/logging" "github.com/gin-gonic/gin" + "github.com/sirupsen/logrus" cshAuth "github.com/computersciencehouse/csh-auth/v2" "go.mongodb.org/mongo-driver/v2/bson" @@ -27,12 +29,13 @@ func GetHomePage(c *gin.Context) { counters, err := database.GetAllCounters(c) if err != nil { + logging.Logger.WithFields(logrus.Fields{"error": err, "module": "api", "method": "GetHomePage"}).Warn("Unable to load counters!") c.JSON(http.StatusInternalServerError, gin.H{"error": "Unable to load counters!"}) return } sort.Slice(counters, func(i, j int) bool { - return counters[i].LastReset.Timestamp.After(counters[j].LastReset.Timestamp) + return counters[i].LastReset.Timestamp > counters[j].LastReset.Timestamp }) c.HTML(http.StatusOK, "index.html", gin.H{ diff --git a/database/reset.go b/database/reset.go index 0ba59d5..8474c7b 100644 --- a/database/reset.go +++ b/database/reset.go @@ -14,7 +14,7 @@ type Reset struct { UserID string `bson:"uuid"` Reporter string `bson:"reporter"` Description string `bson:"description"` - Timestamp time.Time `bson:"timestamp"` + Timestamp int64 `bson:"timestamp"` } func (r *Reset) IDHex() string { diff --git a/templates/counter.tmpl b/templates/counter.tmpl index 536d758..a92e345 100644 --- a/templates/counter.tmpl +++ b/templates/counter.tmpl @@ -130,7 +130,7 @@ }) document.querySelectorAll(".days-since").forEach(el => { - const days = Math.floor((Date.now() - new Date(el.dataset.timestamp)) / 86400000); + const days = Math.floor((Date.now() - (el.dataset.timestamp*1000)) / 86400000); el.textContent = days; }); })(); diff --git a/templates/index.html b/templates/index.html index ba940d8..2d5d935 100644 --- a/templates/index.html +++ b/templates/index.html @@ -28,7 +28,7 @@

'use strict' document.querySelectorAll(".days-since").forEach(el => { - const days = Math.floor((Date.now() - new Date(el.dataset.timestamp)) / 86400000); + const days = Math.floor((Date.now() - (el.dataset.timestamp*1000)) / 86400000); el.textContent = days; }); diff --git a/util.go b/util.go index 5c8310b..3b429cc 100644 --- a/util.go +++ b/util.go @@ -39,7 +39,7 @@ func IsActiveRTP(user *cshAuth.Claims) bool { return slices.Contains(user.Groups, "active-rtp") } -func TranslateTime(inputTime string) time.Time { +func TranslateTime(inputTime string) int64 { timeZone, _ := time.LoadLocation("America/New_York") currentTime := time.Now() @@ -52,5 +52,6 @@ func TranslateTime(inputTime string) time.Time { if timeConverted.After(currentTime) { timeConverted = currentTime } - return timeConverted + + return timeConverted.Unix() }