🐛 Fix TimeZone issue

This commit is contained in:
LittleSheep 2024-12-22 23:34:53 +08:00
parent 0e4c0e5017
commit 8cd7dca8aa

View File

@ -371,7 +371,7 @@ func NewPost(user models.Publisher, item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 { if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil item.Alias = nil
} }
if item.PublishedAt != nil && item.PublishedAt.Unix() < time.Now().Unix() { if item.PublishedAt != nil && item.PublishedAt.UTC().Unix() < time.Now().UTC().Unix() {
return item, fmt.Errorf("post cannot be published before now") return item, fmt.Errorf("post cannot be published before now")
} }
@ -460,7 +460,7 @@ func EditPost(item models.Post) (models.Post, error) {
if item.Alias != nil && len(*item.Alias) == 0 { if item.Alias != nil && len(*item.Alias) == 0 {
item.Alias = nil item.Alias = nil
} }
if item.PublishedAt != nil && item.PublishedAt.Unix() < item.CreatedAt.Unix() { if item.PublishedAt != nil && item.PublishedAt.UTC().Unix() < item.CreatedAt.UTC().Unix() {
return item, fmt.Errorf("post cannot be published before it is created") return item, fmt.Errorf("post cannot be published before it is created")
} }