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

support for date format RFC3339 #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 23 additions & 3 deletions pkg/v2/prop/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package prop

import (
"fmt"
"github.com/imulab/go-scim/pkg/v2/spec"
"time"

"github.com/imulab/go-scim/pkg/v2/spec"
)

// NewDateTime creates a new dateTime property associated with attribute.
Expand Down Expand Up @@ -110,8 +111,16 @@ func (p *dateTimeProperty) Replace(value interface{}) (*Event, error) {
}

t, err := p.fromISO8601(s)

var err2 error

if err != nil {
return nil, err

t, err2 = p.fromRFC3339(s)

if err2 != nil {
return nil, fmt.Errorf("%s %s", err, err2)
}
}

p.dirty = true
Expand Down Expand Up @@ -175,6 +184,14 @@ func (p *dateTimeProperty) fromISO8601(value string) (time.Time, error) {
return t, nil
}

func (p *dateTimeProperty) fromRFC3339(value string) (time.Time, error) {
t, err := time.Parse(time.RFC3339, value)
if err != nil {
return time.Time{}, fmt.Errorf("%w, value for '%s' does not conform to RFC3339", spec.ErrInvalidValue, p.attr.Path())
}
return t, nil
}

func (p *dateTimeProperty) EqualsTo(value interface{}) bool {
return p.compareThisAndValue(value, func(this time.Time, that time.Time) bool {
return this.Equal(that)
Expand Down Expand Up @@ -217,7 +234,10 @@ func (p *dateTimeProperty) compareThisAndValue(value interface{}, comparator fun

t, err := p.fromISO8601(s)
if err != nil {
return false
t, err = p.fromRFC3339(s)
if err != nil {
return false
}
}

return comparator(*(p.value), t)
Expand Down