Added EndTime and Duration to object unmarshalling

This commit is contained in:
Marius Orcsik 2018-12-23 17:12:26 +01:00
parent d1e2ae9598
commit 9e3d0a68a1
No known key found for this signature in database
GPG key ID: 8218F7122969D484
3 changed files with 14 additions and 0 deletions

View file

@ -541,6 +541,8 @@ func (o *Object) UnmarshalJSON(data []byte) error {
o.InReplyTo = getAPItem(data, "inReplyTo")
o.Published = getAPTime(data, "published")
o.StartTime = getAPTime(data, "startTime")
o.EndTime = getAPTime(data, "endTime")
o.Duration = getAPDuration(data, "duration")
o.Icon = getAPItem(data, "icon")
o.Image = getAPItem(data, "image")
o.Updated = getAPTime(data, "updated")

View file

@ -345,6 +345,12 @@ func validateEmptyObject(o Object, t *testing.T) {
if !o.Updated.IsZero() {
t.Errorf("Unmarshalled object %T should have empty Updated, received %q", o, o.Updated)
}
if !o.EndTime.IsZero() {
t.Errorf("Unmarshalled object %T should have empty EndTime, received %q", o, o.EndTime)
}
if o.Duration != 0 {
t.Errorf("Unmarshalled object %T should have empty Duration, received %q", o, o.Duration)
}
if len(o.To) > 0 {
t.Errorf("Unmarshalled object %T should have empty To, received %q", o, o.To)
}

View file

@ -99,6 +99,12 @@ func getAPTime(data []byte, prop string) time.Time {
return t
}
func getAPDuration(data []byte, prop string) time.Duration {
str, _ := jsonparser.GetUnsafeString(data, prop)
d, _ := time.ParseDuration(str)
return d
}
func unmarshalToAPObject(data []byte) Item {
if _, err := url.ParseRequestURI(string(data)); err == nil {
// try to see if it's an IRI