Skip to content

Commit 974b93c

Browse files
authored
Merge pull request #30 from aisa-it/fix/targetDateFormat
fix target dete format
2 parents 5684865 + 43a3e7a commit 974b93c

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

aiplan.go/internal/aiplan/activity-tracker/update.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package tracker
33

44
import (
55
"fmt"
6+
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/types"
7+
"time"
68

79
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/dao"
810
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/utils"
@@ -330,6 +332,15 @@ func entityColorUpdate[E dao.Entity, A dao.Activity](tracker *ActivitiesTracker,
330332
// - []A: список обновленных Activity (если произошла ошибка, возвращает nil и ошибку).
331333
// - error: ошибка, произошедшая при обновлении (если произошла ошибка, возвращает nil).
332334
func entityTargetDateUpdate[E dao.Entity, A dao.Activity](tracker *ActivitiesTracker, requestedData map[string]interface{}, currentInstance map[string]interface{}, entity E, actor dao.User) ([]A, error) {
335+
if v, ok := requestedData["target_date"]; ok && v != nil {
336+
currentTZ := types.TimeZone(*time.Local)
337+
d, _ := utils.FormatDateStr(v.(string), "02.01.2006 15:04 MST", &currentTZ)
338+
requestedData["target_date"] = d
339+
}
340+
if v, ok := currentInstance["target_date"]; ok && v != nil {
341+
d, _ := utils.FormatDateStr(v.(string), "02.01.2006 15:04 MST", nil)
342+
currentInstance["target_date"] = d
343+
}
333344
return entityFieldUpdate[E, A]("target_date", nil, nil, tracker, requestedData, currentInstance, entity, actor)
334345
}
335346

aiplan.go/internal/aiplan/http-issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,14 @@ func (s *Services) updateIssue(c echo.Context) error {
10161016
var targetDate *string
10171017
if val, ok := data["target_date"]; ok {
10181018
if issue.TargetDate != nil {
1019-
if date, err := utils.FormatDateStr(issue.TargetDate.String(), "02.01.2006 15:04 -0700", nil); err != nil {
1019+
if date, err := utils.FormatDateStr(issue.TargetDate.String(), "2006-01-02 15:04:05Z07:00", nil); err != nil {
10201020
return EErrorDefined(c, apierrors.ErrGeneric)
10211021
} else {
10221022
issueMapOld["target_date_activity_val"] = date
10231023
}
10241024
}
10251025
if val != nil {
1026-
date, err := utils.FormatDateStr(val.(string), "02.01.2006 15:04 -0700", nil)
1026+
date, err := utils.FormatDateStr(val.(string), "2006-01-02 15:04:05Z07:00", nil)
10271027
if err != nil {
10281028
return EErrorDefined(c, apierrors.ErrGeneric)
10291029
}

aiplan.go/internal/aiplan/notifications/tg-issue-activity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ func (tni *TgNotifyIssue) LogActivity(activity dao.IssueActivity) {
290290
oldValue = capitalizeFirst(oldValue)
291291
newValue = capitalizeFirst(newValue)
292292
} else if *activity.Field == "target_date" {
293-
newT, err := FormatDate(newValue, "02.01.2006", nil)
294-
oldValue, _ = FormatDate(oldValue, "02.01.2006", nil)
293+
newT, err := FormatDate(newValue, "02.01.2006 15:04 MST", nil)
294+
oldValue, _ = FormatDate(oldValue, "02.01.2006 15:04 MST", nil)
295295
if newValue == "<nil>" {
296296
newValue = ""
297297
}

aiplan.go/internal/aiplan/notifications/util.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func FormatDate(dateStr, outFormat string, tz *types.TimeZone) (string, error) {
8484
"02.01.2006 15:04 MST",
8585
"02.01.2006 15:04 -0700",
8686
"02.01.2006",
87+
"2006-01-02 15:04:05Z07:00",
8788
}
8889

8990
var t time.Time

aiplan.go/internal/aiplan/utils/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,15 @@ func FormatDate(dateStr string) (time.Time, error) {
253253
"2006-01-02T15:04:05",
254254
"2006-01-02T15:04:05.000Z",
255255
"2006-01-02T15:04:05Z07:00",
256+
"2006-01-02 15:04:05Z07:00",
256257
"2006-01-02 15:04:05",
257258
"2006-01-02 15:04:05 -0700 MST",
258259
"2006-01-02",
259260
"02.01.2006 15:04 MST",
260261
"02.01.2006 15:04 -0700",
261262
"02.01.2006",
263+
"2006-01-02 15:04:05-07",
264+
"2006-01-02 15:04:05 -0700",
262265
}
263266

264267
var t time.Time

0 commit comments

Comments
 (0)