1
0

Dates are now of type time.Time.

This commit is contained in:
Alexander Andreev 2023-02-05 16:28:55 +04:00
parent 729e58fdca
commit 309044f651
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
3 changed files with 19 additions and 13 deletions

View File

@ -4,6 +4,7 @@ import (
"database/sql"
_ "embed"
"fmt"
"time"
"git.arav.top/Arav/justguestbook/guestbook"
_ "github.com/mattn/go-sqlite3"
@ -137,9 +138,14 @@ func (d *SQLiteDatabase) Entries(page, pageSize int64) (entries []*guestbook.Ent
}
if reply_message.Valid /* reply_created is also valid if reply is */ {
date, err := time.Parse(guestbook.DateFormat, reply_created.String)
if err != nil {
return nil, err
}
entry.Reply = &guestbook.Reply{
ID: entry.ID,
Created: reply_created.String,
Created: date,
Message: reply_message.String}
}

View File

@ -6,13 +6,13 @@ import (
)
type Entry struct {
ID int64 `json:"entry_id"`
Created string `json:"created"`
Name string `json:"name"`
Website string `json:"website,omitempty"`
Message string `json:"message"`
HideWebsite bool `json:"hide_website,omitempty"`
Reply *Reply `json:"reply,omitempty"`
ID int64 `json:"entry_id"`
Created time.Time `json:"created"`
Name string `json:"name"`
Website string `json:"website,omitempty"`
Message string `json:"message"`
HideWebsite bool `json:"hide_website,omitempty"`
Reply *Reply `json:"reply,omitempty"`
}
func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) {
@ -21,7 +21,7 @@ func NewEntry(name, message, website string, hideWebsite bool) (*Entry, error) {
}
return &Entry{
Created: time.Now().UTC().Format(DateFormat),
Created: time.Now().UTC(),
Name: name,
Website: website,
HideWebsite: hideWebsite,

View File

@ -6,9 +6,9 @@ import (
)
type Reply struct {
ID int64 `json:"-"`
Created string `json:"created,omitempty"`
Message string `json:"message"`
ID int64 `json:"-"`
Created time.Time `json:"created,omitempty"`
Message string `json:"message"`
}
func NewReply(entryID int64, message string) (*Reply, error) {
@ -18,6 +18,6 @@ func NewReply(entryID int64, message string) (*Reply, error) {
return &Reply{
ID: entryID,
Created: time.Now().UTC().Format(DateFormat),
Created: time.Now().UTC(),
Message: message}, nil
}