Added EndTime and Duration to object unmarshalling
This commit is contained in:
parent
d1e2ae9598
commit
9e3d0a68a1
3 changed files with 14 additions and 0 deletions
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue