Skip to content

Commit

Permalink
bug: get timezone from datetime instead of event data (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmartingr authored Jul 26, 2023
1 parent 728630e commit 585e821
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
11 changes: 0 additions & 11 deletions server/remote/date_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package remote
import (
"time"

"google.golang.org/api/calendar/v3"

"github.com/mattermost/mattermost-plugin-mscalendar/server/utils/tz"
)

Expand Down Expand Up @@ -35,15 +33,6 @@ func NewDateTime(t time.Time, timeZone string) *DateTime {
}
}

// NewGoogleDateTime creates a DateTime that is compatible with Google's API.
func NewGoogleDateTime(dateTime *calendar.EventDateTime) *DateTime {
t, _ := time.Parse(time.RFC3339, dateTime.DateTime)
return &DateTime{
DateTime: t.Format(RFC3339NanoNoTimezone),
TimeZone: dateTime.TimeZone,
}
}

// String returns the RFC3339 representation of the provided datetime. UndefinedDatetime if not set.
func (dt DateTime) String() string {
t := dt.Time()
Expand Down
20 changes: 17 additions & 3 deletions server/remote/gcal/get_default_calendar_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var responseStatusConversion = map[string]string{
GoogleResponseStatusNone: ResponseNone,
}

func (c *client) GetDefaultCalendarView(remoteUserID string, start, end time.Time) ([]*remote.Event, error) {
func (c *client) GetDefaultCalendarView(_ string, start, end time.Time) ([]*remote.Event, error) {
service, err := calendar.NewService(context.Background(), option.WithHTTPClient(c.httpClient))
if err != nil {
return nil, errors.Wrap(err, "gcal GetDefaultCalendarView, error creating service")
Expand Down Expand Up @@ -73,14 +73,28 @@ func (c *client) GetDefaultCalendarView(remoteUserID string, start, end time.Tim
return result, nil
}

func convertGCalEventDateTimeToRemoteDateTime(dt *calendar.EventDateTime) *remote.DateTime {
t, _ := time.Parse(time.RFC3339, dt.DateTime)

location := dt.TimeZone
if t.Location() != nil {
location = t.Location().String()
}

return &remote.DateTime{
DateTime: t.Format(remote.RFC3339NanoNoTimezone),
TimeZone: location,
}
}

func convertGCalEventToRemoteEvent(event *calendar.Event) *remote.Event {
showAs := RemoteEventBusy
if event.Transparency == GoogleEventFree {
showAs = RemoteEventFree
}

start := remote.NewGoogleDateTime(event.Start)
end := remote.NewGoogleDateTime(event.End)
start := convertGCalEventDateTimeToRemoteDateTime(event.Start)
end := convertGCalEventDateTimeToRemoteDateTime(event.End)

location := &remote.Location{
DisplayName: event.Location,
Expand Down

0 comments on commit 585e821

Please sign in to comment.