aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-11-04 23:46:40 -0800
committerGitHub <noreply@github.com>2024-11-05 07:46:40 +0000
commit24b83ff63e7ffd3d412bc9b509102aa2c507ced1 (patch)
tree3f18ed68bb62f3a597d2417481c7525bf1ac8a41 /routers/api/v1
parent1887c75c35c1d16372b1dbe2b792e374b558ce1f (diff)
downloadgitea-24b83ff63e7ffd3d412bc9b509102aa2c507ced1.tar.gz
gitea-24b83ff63e7ffd3d412bc9b509102aa2c507ced1.zip
Fix milestone deadline and date related problems (#32339)
Use zero instead of 9999-12-31 for deadline Fix #32291 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/repo/issue.go12
-rw-r--r--routers/api/v1/repo/milestone.go14
2 files changed, 9 insertions, 17 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index e86fb3ccb1..cbe709c030 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
+ "code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
issue_service "code.gitea.io/gitea/services/issue"
@@ -1046,18 +1047,11 @@ func UpdateIssueDeadline(ctx *context.APIContext) {
return
}
- var deadlineUnix timeutil.TimeStamp
- var deadline time.Time
- if form.Deadline != nil && !form.Deadline.IsZero() {
- deadline = time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(),
- 23, 59, 59, 0, time.Local)
- deadlineUnix = timeutil.TimeStamp(deadline.Unix())
- }
-
+ deadlineUnix, _ := common.ParseAPIDeadlineToEndOfDay(form.Deadline)
if err := issues_model.UpdateIssueDeadline(ctx, issue, deadlineUnix, ctx.Doer); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateIssueDeadline", err)
return
}
- ctx.JSON(http.StatusCreated, api.IssueDeadline{Deadline: &deadline})
+ ctx.JSON(http.StatusCreated, api.IssueDeadline{Deadline: deadlineUnix.AsTimePtr()})
}
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index abe9e4006a..78907c85a5 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -7,7 +7,6 @@ package repo
import (
"net/http"
"strconv"
- "time"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
@@ -16,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
+ "code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/convert"
)
@@ -155,16 +155,16 @@ func CreateMilestone(ctx *context.APIContext) {
// "$ref": "#/responses/notFound"
form := web.GetForm(ctx).(*api.CreateMilestoneOption)
- if form.Deadline == nil {
- defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
- form.Deadline = &defaultDeadline
+ var deadlineUnix int64
+ if form.Deadline != nil {
+ deadlineUnix = form.Deadline.Unix()
}
milestone := &issues_model.Milestone{
RepoID: ctx.Repo.Repository.ID,
Name: form.Title,
Content: form.Description,
- DeadlineUnix: timeutil.TimeStamp(form.Deadline.Unix()),
+ DeadlineUnix: timeutil.TimeStamp(deadlineUnix),
}
if form.State == "closed" {
@@ -225,9 +225,7 @@ func EditMilestone(ctx *context.APIContext) {
if form.Description != nil {
milestone.Content = *form.Description
}
- if form.Deadline != nil && !form.Deadline.IsZero() {
- milestone.DeadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
- }
+ milestone.DeadlineUnix, _ = common.ParseAPIDeadlineToEndOfDay(form.Deadline)
oldIsClosed := milestone.IsClosed
if form.State != nil {