minor: x/jsonx.ParseISO8601

more features designed for the past 2-3 months to come, this is just a hotfix
This commit is contained in:
Gerasimos (Makis) Maropoulos 2024-04-08 20:39:29 +03:00
parent 19a72ddc84
commit 1d106d80a7
No known key found for this signature in database
GPG Key ID: D6032D1840F48BEC

View File

@ -75,6 +75,7 @@ func ParseISO8601(s string) (ISO8601, error) {
err error err error
) )
/*
// Check if the string contains a timezone offset after the 'T' character. // Check if the string contains a timezone offset after the 'T' character.
hasOffset := strings.Contains(s, "Z") || (strings.Index(s, "+") > strings.Index(s, "T")) || (strings.Index(s, "-") > strings.Index(s, "T")) hasOffset := strings.Contains(s, "Z") || (strings.Index(s, "+") > strings.Index(s, "T")) || (strings.Index(s, "-") > strings.Index(s, "T"))
@ -94,8 +95,8 @@ func ParseISO8601(s string) (ISO8601, error) {
} }
return ISO8601(tt), nil return ISO8601(tt), nil
*/
/*
if idx := strings.LastIndexFunc(s, startUTCOffsetIndexFunc); idx > 18 { // should have some distance, with and without milliseconds if idx := strings.LastIndexFunc(s, startUTCOffsetIndexFunc); idx > 18 { // should have some distance, with and without milliseconds
length := parseSignedOffset(s[idx:]) length := parseSignedOffset(s[idx:])
@ -117,17 +118,17 @@ func ParseISO8601(s string) (ISO8601, error) {
if strings.Contains(s, ".") { if strings.Contains(s, ".") {
tt, err = time.ParseInLocation(ISO8601ZUTCOffsetLayoutWithMicroseconds, s, loc) tt, err = time.ParseInLocation(ISO8601ZUTCOffsetLayoutWithMicroseconds, s, loc)
} else { } else {
tt, err = time.ParseInLocation(ISO8601ZUTCOffsetLayout, s, loc) tt, err = time.ParseInLocation(ISO8601ZUTCOffsetLayoutWithoutMicroseconds, s, loc)
} }
} else { // Local or UTC. } else { // Local or UTC.
if strings.Contains(s, ".") { if strings.Contains(s, ".") {
tt, err = time.Parse(ISO8601ZUTCOffsetLayoutWithMicroseconds, s) tt, err = time.Parse(ISO8601ZUTCOffsetLayoutWithMicroseconds, s)
} else { } else {
tt, err = time.Parse(ISO8601ZUTCOffsetLayout, s) tt, err = time.Parse(ISO8601ZUTCOffsetLayoutWithoutMicroseconds, s)
} }
} }
} else if s[len(s)-1] == 'Z' { } else if s[len(s)-1] == 'Z' {
tt, err = time.Parse(ISO8601ZLayout, s) tt, err = time.Parse(ISO8601LayoutWithTimezone, s)
} else { } else {
tt, err = time.Parse(ISO8601Layout, s) tt, err = time.Parse(ISO8601Layout, s)
} }
@ -136,7 +137,6 @@ func ParseISO8601(s string) (ISO8601, error) {
return ISO8601{}, fmt.Errorf("ISO8601: %w", err) return ISO8601{}, fmt.Errorf("ISO8601: %w", err)
} }
return ISO8601(tt), nil return ISO8601(tt), nil
*/
} }
func parseWithOffset(s string) (time.Time, error) { func parseWithOffset(s string) (time.Time, error) {