Ensure all dates returned are ISO8601
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type AuthToken struct {
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
)
|
||||
|
||||
type Conversation struct {
|
||||
Date time.Time `json:"date"`
|
||||
Participants []string `json:"participantDisplayNames"`
|
||||
DisplayName *string `json:"displayName,omitempty"` // Optional
|
||||
UnreadCount int `json:"unreadCount"`
|
||||
LastMessagePreview string `json:"lastMessagePreview"`
|
||||
LastMessage Message `json:"lastMessage"`
|
||||
Guid string `json:"guid"`
|
||||
Date Date `json:"date"`
|
||||
Participants []string `json:"participantDisplayNames"`
|
||||
DisplayName *string `json:"displayName,omitempty"` // Optional
|
||||
UnreadCount int `json:"unreadCount"`
|
||||
LastMessagePreview string `json:"lastMessagePreview"`
|
||||
LastMessage Message `json:"lastMessage"`
|
||||
Guid string `json:"guid"`
|
||||
}
|
||||
|
||||
func (c *Conversation) GetDisplayName() string {
|
||||
@@ -27,7 +27,7 @@ func (c *Conversation) GetDisplayName() string {
|
||||
|
||||
func (c *Conversation) MarshalZerologObject(e *zerolog.Event) {
|
||||
e.Str("guid", c.Guid)
|
||||
e.Time("date", c.Date)
|
||||
e.Time("date", time.Time(c.Date))
|
||||
e.Int("unreadCount", c.UnreadCount)
|
||||
e.Str("lastMessagePreview", c.LastMessagePreview)
|
||||
e.Strs("participants", c.Participants)
|
||||
|
||||
30
model/date.go
Normal file
30
model/date.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Date time.Time
|
||||
|
||||
func (d Date) Equal(other Date) bool {
|
||||
return time.Time(d).Equal(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) After(other Date) bool {
|
||||
return time.Time(d).After(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) Before(other Date) bool {
|
||||
return time.Time(d).Before(time.Time(other))
|
||||
}
|
||||
|
||||
func (d Date) Format(layout string) string {
|
||||
return time.Time(d).Format(layout)
|
||||
}
|
||||
|
||||
func (t Date) MarshalJSON() ([]byte, error) {
|
||||
// Must use ISO8601
|
||||
formatted := fmt.Sprintf("\"%s\"", time.Time(t).Format("2006-01-02T15:04:05+00:00"))
|
||||
return []byte(formatted), nil
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Text string `json:"text"`
|
||||
Guid string `json:"guid"`
|
||||
Sender *string `json:"sender,omitempty"` // Optional: nil means from "me"
|
||||
Date time.Time `json:"date"`
|
||||
Text string `json:"text"`
|
||||
Guid string `json:"guid"`
|
||||
Sender *string `json:"sender,omitempty"` // Optional: nil means from "me"
|
||||
Date Date `json:"date"`
|
||||
|
||||
// Map of attachment GUID to attachment metadata
|
||||
Attachments *map[string]AttributionInfo `json:"attachmentMetadata,omitempty"` // Optional
|
||||
@@ -24,7 +23,7 @@ type AttributionInfo struct {
|
||||
func (c Message) MarshalZerologObject(e *zerolog.Event) {
|
||||
e.Str("guid", c.Guid)
|
||||
e.Str("text", c.Text)
|
||||
e.Time("date", c.Date)
|
||||
e.Time("date", time.Time(c.Date))
|
||||
|
||||
if c.Sender != nil {
|
||||
e.Str("sender", *c.Sender)
|
||||
|
||||
Reference in New Issue
Block a user