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
This commit is contained in:
Matt Baer 2018-12-08 12:51:27 -05:00
parent 6f4c004e8c
commit daaa4564bb
1 changed files with 8 additions and 0 deletions

View File

@ -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()
}
}
}