feat: Add YYYY-MM-DD date format support for Pagure milestone migration (#10299)

The change migrates the milestone's deadline in a semantic time format understood by the database.

Please note that this change is in addition to that of !10169.

Fixes https://forge.fedoraproject.org/forge/forge/issues/306

Signed-off-by: Akashdeep Dhar <akashdeep.dhar@gmail.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10299
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Akashdeep Dhar <akashdeep.dhar@gmail.com>
Co-committed-by: Akashdeep Dhar <akashdeep.dhar@gmail.com>
This commit is contained in:
Akashdeep Dhar 2025-12-09 21:06:29 +01:00 committed by Gusted
parent 91575ca285
commit be43dbfcfb
2 changed files with 50 additions and 3 deletions

View file

@ -178,13 +178,20 @@ func processDate(dateStr *string) time.Time {
return date
}
// Try parsing as Unix timestamp first
unix, err := strconv.Atoi(*dateStr)
if err != nil {
log.Error("Error:", err)
if err == nil {
date = time.Unix(int64(unix), 0)
return date
}
date = time.Unix(int64(unix), 0)
// Try parsing as YYYY-MM-DD format
parsedDate, err := time.Parse("2006-01-02", *dateStr)
if err == nil {
return parsedDate
}
log.Error("Error parsing date '%s': %v", *dateStr, err)
return date
}

View file

@ -635,3 +635,43 @@ func TestPagureDownloadRepoWithPrivateIssues(t *testing.T) {
},
}, comments)
}
func TestProcessDate(t *testing.T) {
tests := []struct {
name string
input *string
expected time.Time
}{
{
name: "nil input",
input: nil,
expected: time.Time{},
},
{
name: "empty string",
input: strPtr(""),
expected: time.Time{},
},
{
name: "unix timestamp",
input: strPtr("1609459200"),
expected: time.Unix(1609459200, 0),
},
{
name: "YYYY-MM-DD format",
input: strPtr("2025-12-12"),
expected: time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := processDate(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func strPtr(s string) *string {
return &s
}