Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime parsing is incorrect #85

Open
aliotta opened this issue Jun 17, 2021 · 1 comment
Open

DateTime parsing is incorrect #85

aliotta opened this issue Jun 17, 2021 · 1 comment
Assignees

Comments

@aliotta
Copy link

aliotta commented Jun 17, 2021

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
Copy link
Owner

imulab commented Jun 17, 2021

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.

@imulab imulab self-assigned this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants