DateTime parsing is incorrect
aliotta opened this issue · 1 comments
aliotta commented
Scim defines its datetime field (https://datatracker.ietf.org/doc/html/rfc7643#section-2.3.5) as following the w3 xsd schema (https://www.w3.org/TR/xmlschema11-2/#dateTime). Currently the dateTime validation fails for dateTime with timezones +00:00. Modifying the fromIso method to the bellow seems to do the trick.
func (p *dateTimeProperty) fromISO8601(str string) (time.Time, error) {
const DateTimeFormat = "2006-01-02T15:04:05.999999999-07:00"
const DateTimeNoTimezone = "2006-01-02T15:04:05.999999999"
const DateTimeUTC = "2006-01-02T15:04:05.999999999Z"
var (
val time.Time
err error
z = str[len(str)-6]
utc = str[len(str)-1]
)
if z == '+' || z == '-' {
val, err = time.Parse(DateTimeFormat, str)
} else if utc == 'Z' {
val, err = time.Parse(DateTimeUTC, str)
} else {
val, err = time.Parse(DateTimeNoTimezone, str)
}
if err != nil {
return time.Time{}, fmt.Errorf("%w, value for '%s' does not conform to ISO8601", spec.ErrInvalidValue, p.attr.Path())
}
return val, nil
}
imulab commented
I have always been aware of this problem, but unable to solve it. Thanks a lot for contributing the above snippet. I will take a look and make some test cases.