-
Notifications
You must be signed in to change notification settings - Fork 38
/
ResponseStatus.go
47 lines (39 loc) · 1.4 KB
/
ResponseStatus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package msgraph
import (
"encoding/json"
"fmt"
"time"
)
// ResponseStatus represents the response status for an Attendee to a CalendarEvent or just for a CalendarEvent
type ResponseStatus struct {
Response string // status of the response, may be organizer, accepted, declined etc.
Time time.Time // represents the time when the response was performed
}
func (s ResponseStatus) String() string {
return fmt.Sprintf("Response: %s, Time: %s", s.Response, s.Time.Format(time.RFC3339Nano))
}
// Equal compares the ResponseStatus to the other Response status and returns true
// if the Response and time is equal
func (s ResponseStatus) Equal(other ResponseStatus) bool {
return s.Response == other.Response && s.Time.Equal(other.Time)
}
// UnmarshalJSON implements the json unmarshal to be used by the json-library
func (s *ResponseStatus) UnmarshalJSON(data []byte) error {
tmp := struct {
Response string `json:"response"`
Timestamp string `json:"time"`
}{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
if tmp.Response == "" {
return fmt.Errorf("response-field is empty")
}
s.Response = tmp.Response
s.Time, err = time.Parse(time.RFC3339Nano, tmp.Timestamp) // the timeZone is normally ALWAYS UTC, microsoft converts time date & time to that, but it does not matter here
if err != nil {
return fmt.Errorf("cannot parse timestamp with RFC3339Nano: %v", err)
}
return nil
}