mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-05 19:52:01 +00:00
ab1979bcfb
Due dates set through the API were stored inconsistently. The create endpoints kept the raw timestamp, issue and pull request edits used end of day in the client's offset, and only the deadline and milestone edit endpoints normalized to end of day in the server's UI timezone like the web UI does. All API due dates now go through `ParseAPIDeadlineToEndOfDay`. Editing a pull request with `unset_due_date: false` and no `due_date` dereferenced a nil pointer and returned 500. It now shares the issue edit logic and returns 400. Related to https://github.com/go-gitea/gitea/issues/37620, which is about the web sidebar and isn't fixed here. --------- Co-authored-by: silverwind <me@silverwind.io>
31 lines
828 B
Go
31 lines
828 B
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package common
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitea.dev/modules/setting"
|
|
"gitea.dev/modules/timeutil"
|
|
)
|
|
|
|
func ParseDeadlineDateToEndOfDay(date string) (timeutil.TimeStamp, error) {
|
|
if date == "" {
|
|
return 0, nil
|
|
}
|
|
deadline, err := time.ParseInLocation("2006-01-02", date, setting.DefaultUILocation)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
deadline = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, deadline.Location())
|
|
return timeutil.TimeStamp(deadline.Unix()), nil
|
|
}
|
|
|
|
func ParseAPIDeadlineToEndOfDay(t *time.Time) timeutil.TimeStamp {
|
|
if t == nil || t.IsZero() || t.Unix() == 0 {
|
|
return 0
|
|
}
|
|
return timeutil.TimeStamp(time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, setting.DefaultUILocation).Unix())
|
|
}
|