From: Jeff Halter Date: Fri, 27 May 2022 17:55:57 +0000 (-0700) Subject: Simplify news article timestamping X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/3c9b1dcdf40474396a3b035d548417b84a123164?ds=inline Simplify news article timestamping --- diff --git a/hotline/news.go b/hotline/news.go index 7a5c30c..a6b8372 100644 --- a/hotline/news.go +++ b/hotline/news.go @@ -5,7 +5,6 @@ import ( "crypto/rand" "encoding/binary" "sort" - "time" ) type ThreadedNews struct { @@ -250,25 +249,3 @@ func (s *Server) GetNewsCatByPath(paths []string) map[string]NewsCategoryListDat } return cats } - -// News article date field contains this structure: -// Year 2 -// Milliseconds 2 (seriously?) -// Seconds 4 -func NewsDate() []byte { - t := time.Now() - ms := []byte{0, 0} - seconds := []byte{0, 0, 0, 0} - - year := []byte{0, 0} - binary.BigEndian.PutUint16(year, uint16(t.Year())) - - yearStart := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local) - - binary.BigEndian.PutUint32(seconds, uint32(t.Sub(yearStart).Seconds())) - - date := append(year, ms...) - date = append(date, seconds...) - - return date -} diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 5aa6984..2c5a930 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -1140,7 +1140,7 @@ func HandlePostNewsArt(cc *ClientConn, t *Transaction) (res []Transaction, err e newArt := NewsArtData{ Title: string(t.GetField(fieldNewsArtTitle).Data), Poster: string(cc.UserName), - Date: NewsDate(), + Date: toHotlineTime(time.Now()), PrevArt: []byte{0, 0, 0, 0}, NextArt: []byte{0, 0, 0, 0}, ParentArt: append([]byte{0, 0}, t.GetField(fieldNewsArtID).Data...),