Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions pkg/shared/models/custom_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

var customTimeFormat = "2006-01-02T15:04-07:00"

var customTimeParseFormats = []string{time.RFC3339, customTimeFormat}

type CustomTime struct {
time.Time
}
Expand All @@ -21,12 +23,18 @@ func (ct *CustomTime) String() string {
//goland:noinspection GoMixedReceiverTypes
func (ct *CustomTime) UnmarshalJSON(data []byte) error {
str := strings.Trim(string(data), `"`) // Remove JSON quotes
parsed, err := time.Parse(customTimeFormat, str)
if err != nil {
return err
var parsed time.Time
var err error

for _, layout := range customTimeParseFormats {
parsed, err = time.Parse(layout, str)
if err == nil {
ct.Time = parsed
return nil
}
}
ct.Time = parsed
return nil

return err
}

//goland:noinspection GoMixedReceiverTypes
Expand Down
5 changes: 5 additions & 0 deletions pkg/shared/models/custom_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ func TestCustomTime_UnmarshalJSON(t *testing.T) {
input: `"2025-04-24T22:19-04:00"`,
expectedStr: "2025-04-24T22:19-04:00",
},
{
name: "valid time with seconds and offset",
input: `"2026-04-14T17:30:00-05:00"`,
expectedStr: "2026-04-14T17:30-05:00",
},
{
name: "invalid format missing T",
input: `"2025-04-25 02:19+00:00"`,
Expand Down