Fix post `created` date in SQLite

We store times in UTC in all other places, but the post.Created logic
when creating a post meant that dates were being stored in a user's
local timezone. This fixes that.

Ref T529
pull/45/head
Matt Baer 6 years ago
parent 6f4c004e8c
commit daaa4564bb
  1. 8
      database.go

@ -574,11 +574,19 @@ func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Pos
}
created := time.Now()
if db.driverName == driverSQLite {
// SQLite stores datetimes in UTC, so convert time.Now() to it here
created = created.UTC()
}
if post.Created != nil {
created, err = time.Parse("2006-01-02T15:04:05Z", *post.Created)
if err != nil {
log.Error("Unable to parse Created time '%s': %v", *post.Created, err)
created = time.Now()
if db.driverName == driverSQLite {
// SQLite stores datetimes in UTC, so convert time.Now() to it here
created = created.UTC()
}
}
}

Loading…
Cancel
Save