File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,12 +21,20 @@ func (ct *CustomTime) String() string {
2121//goland:noinspection GoMixedReceiverTypes
2222func (ct * CustomTime ) UnmarshalJSON (data []byte ) error {
2323 str := strings .Trim (string (data ), `"` ) // Remove JSON quotes
24- parsed , err := time .Parse (customTimeFormat , str )
25- if err != nil {
26- return err
24+
25+ layouts := []string {time .RFC3339 , customTimeFormat }
26+ var parsed time.Time
27+ var err error
28+
29+ for _ , layout := range layouts {
30+ parsed , err = time .Parse (layout , str )
31+ if err == nil {
32+ ct .Time = parsed
33+ return nil
34+ }
2735 }
28- ct . Time = parsed
29- return nil
36+
37+ return err
3038}
3139
3240//goland:noinspection GoMixedReceiverTypes
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ func TestCustomTime_UnmarshalJSON(t *testing.T) {
3535 input : `"2025-04-24T22:19-04:00"` ,
3636 expectedStr : "2025-04-24T22:19-04:00" ,
3737 },
38+ {
39+ name : "valid time with seconds and offset" ,
40+ input : `"2026-04-14T17:30:00-05:00"` ,
41+ expectedStr : "2026-04-14T17:30-05:00" ,
42+ },
3843 {
3944 name : "invalid format missing T" ,
4045 input : `"2025-04-25 02:19+00:00"` ,
You can’t perform that action at this time.
0 commit comments