浏览代码

改进报告时间格式解析

在多个报告相关文件中,增加了对创建时间格式的解析逻辑。通过判断传入的创建时间字符串是否包含冒号,来决定使用日期时间格式还是仅日期格式进行解析。这样可以更灵活地处理用户输入,提高系统的健壮性。
Roc 6 月之前
父节点
当前提交
84d53d4415
共有 3 个文件被更改,包括 16 次插入3 次删除
  1. 5 1
      controllers/report_chapter.go
  2. 5 1
      controllers/report_v2.go
  3. 6 1
      services/report_v2.go

+ 5 - 1
controllers/report_chapter.go

@@ -413,7 +413,11 @@ func (this *ReportController) EditDayWeekChapter() {
 	reportChapterInfo.IsEdit = 1
 	reportChapterInfo.ModifyTime = time.Now()
 	if req.CreateTime != `` {
-		createTime, tmpErr := time.ParseInLocation(utils.FormatDateTime, req.CreateTime, time.Local)
+		formatDate := utils.FormatDateTime
+		if !strings.Contains(req.CreateTime, ":") {
+			formatDate = utils.FormatDate
+		}
+		createTime, tmpErr := time.ParseInLocation(formatDate, req.CreateTime, time.Local)
 		if tmpErr != nil {
 			err = tmpErr
 			return

+ 5 - 1
controllers/report_v2.go

@@ -453,7 +453,11 @@ func (this *ReportController) Add() {
 	item.Stage = maxStage + 1
 	item.ContentSub = html.EscapeString(contentSub)
 	if req.CreateTime != `` {
-		createTime, tmpErr := time.ParseInLocation(utils.FormatDateTime, req.CreateTime, time.Local)
+		formatDate := utils.FormatDateTime
+		if !strings.Contains(req.CreateTime, ":") {
+			formatDate = utils.FormatDate
+		}
+		createTime, tmpErr := time.ParseInLocation(formatDate, req.CreateTime, time.Local)
 		if tmpErr != nil {
 			br.Msg = "时间解析异常"
 			br.ErrMsg = "时间解析异常,Err:" + err.Error()

+ 6 - 1
services/report_v2.go

@@ -15,6 +15,7 @@ import (
 	"os"
 	"path"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -158,7 +159,11 @@ func EditReport(reportInfo *models.Report, req models.EditReq, sysUser *system.A
 	//reportInfo.Content = html.EscapeString(req.Content)	// 编辑不变更具体内容
 	//reportInfo.ContentSub = html.EscapeString(contentSub)	// 编辑不变更具体内容
 	if req.CreateTime != `` {
-		createTime, tmpErr := time.ParseInLocation(utils.FormatDateTime, req.CreateTime, time.Local)
+		formatDate := utils.FormatDateTime
+		if !strings.Contains(req.CreateTime, ":") {
+			formatDate = utils.FormatDate
+		}
+		createTime, tmpErr := time.ParseInLocation(formatDate, req.CreateTime, time.Local)
 		if tmpErr != nil {
 			err = tmpErr
 			return