mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
fix: time in location
This commit is contained in:
20
pkg/cache/cache.go
vendored
20
pkg/cache/cache.go
vendored
@@ -32,6 +32,14 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
// init timezone
|
||||
var err error
|
||||
tools.TimeLocation, err = time.LoadLocation(
|
||||
config.Conf.BlogApp.General.Timezone)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// init store
|
||||
store, err := store.NewStore(config.Conf.Database.Driver,
|
||||
config.Conf.Database.Source)
|
||||
if err != nil {
|
||||
@@ -514,23 +522,25 @@ func (c *Cache) regeneratePages() {
|
||||
gt12Month = len(Ei.Archives) > 12
|
||||
)
|
||||
for _, archive := range c.Archives {
|
||||
t := archive.Time.In(tools.TimeLocation)
|
||||
if gt12Month {
|
||||
year := archive.Time.Format("2006 年")
|
||||
year := t.Format("2006 年")
|
||||
if currentYear != year {
|
||||
currentYear = year
|
||||
buf.WriteString(fmt.Sprintf("\n### %s\n\n", archive.Time.Format("2006 年")))
|
||||
buf.WriteString(fmt.Sprintf("\n### %s\n\n", t.Format("2006 年")))
|
||||
}
|
||||
} else {
|
||||
buf.WriteString(fmt.Sprintf("\n### %s\n\n", archive.Time.Format("2006年1月")))
|
||||
buf.WriteString(fmt.Sprintf("\n### %s\n\n", t.Format("2006年1月")))
|
||||
}
|
||||
for i, article := range archive.Articles {
|
||||
createdAt := article.CreatedAt.In(time.Location)
|
||||
if i == 0 && gt12Month {
|
||||
str := fmt.Sprintf(`* *[%s](/post/%s.html) <span class="date">(%s)</span>`,
|
||||
article.Title, article.Slug, article.CreatedAt.Format("Jan 02, 2006"))
|
||||
article.Title, article.Slug, createdAt.Format("Jan 02, 2006"))
|
||||
buf.WriteString(str)
|
||||
} else {
|
||||
str := fmt.Sprintf(`* [%s](/post/%s.html) <span class="date">(%s)</span>`,
|
||||
article.Title, article.Slug, article.CreatedAt.Format("Jan 02, 2006"))
|
||||
article.Title, article.Slug, createdAt.Format("Jan 02, 2006"))
|
||||
buf.WriteString(str)
|
||||
}
|
||||
buf.WriteByte('\n')
|
||||
|
||||
@@ -48,6 +48,7 @@ type General struct {
|
||||
Length int `yaml:"length"` // 文章预览长度
|
||||
Trash int `yaml:"trash"` // 回收箱文章保留时间
|
||||
Clean int `yaml:"clean"` // 清理回收箱频率
|
||||
Timezone string `yaml:"timezone"` // 时区
|
||||
}
|
||||
|
||||
// Disqus comments
|
||||
|
||||
@@ -227,13 +227,14 @@ func handleAPIPostCreate(c *gin.Context) {
|
||||
cid int
|
||||
)
|
||||
defer func() {
|
||||
now := time.Now().In(tools.TimeLocation)
|
||||
switch do {
|
||||
case "auto": // 自动保存
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"fail": 1, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
c.JSON(http.StatusOK, gin.H{"fail": 1, "time": now.Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"success": 0, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
c.JSON(http.StatusOK, gin.H{"success": 0, "time": now.Format("15:04:05 PM"), "cid": cid})
|
||||
case "save", "publish": // 草稿,发布
|
||||
if err != nil {
|
||||
responseNotice(c, NoticeNotice, err.Error(), "")
|
||||
@@ -498,9 +499,9 @@ func handleAPIQiniuDelete(c *gin.Context) {
|
||||
|
||||
// parseLocationDate 解析日期
|
||||
func parseLocationDate(date string) time.Time {
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04", date, time.Local)
|
||||
t, err := time.ParseInLocation("2006-01-02 15:04", date, tools.TimeLocation)
|
||||
if err == nil {
|
||||
return t
|
||||
return t.UTC()
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user