private MeetingTimes BuildRequestBody(Meeting meeting) { var result = new MeetingTimes { MeetingDuration = "PT30M", Attendees = new List<MeetingTimes.Attendee>(), TimeConstraint = new TimeConstraint { Timeslots = new List<MeetingTimeSlot>() }, LocationConstraint = new LocationConstraint() { IsRequired = false, Locations = new List<Location>() }, MaxCandidates = 20, }; foreach (var a in meeting.Attendees ?? Enumerable.Empty<Attendee>()) { if (meeting.Organizer == null || !a.EmailAddress.IsEqualTo(meeting.Organizer.EmailAddress)) { result.Attendees.Add(new MeetingTimes.Attendee { EmailAddress = a.EmailAddress }); } } var date = meeting.Start.DateTime; // From 8AM to 6PM local time var start = new DateTime(date.Year, date.Month, date.Day, 8, 0, 0, DateTimeKind.Local); var end = new DateTime(date.Year, date.Month, date.Day, 18, 0, 0, DateTimeKind.Local); start = start.ToUniversalTime(); end = end.ToUniversalTime(); var timeSlot = new MeetingTimeSlot { Start = new MeetingTimeSlot.TimeDescriptor { Date = start.DateToApiString(), Time = start.TimeOfDay.ToString(), TimeZone = "UTC" }, End = new MeetingTimeSlot.TimeDescriptor { Date = end.DateToApiString(), Time = end.TimeOfDay.ToString(), TimeZone = "UTC" } }; result.TimeConstraint.Timeslots.Add(timeSlot); if (!string.IsNullOrEmpty(meeting.Location.DisplayName)) { result.LocationConstraint.Locations.Add(new Location { DisplayName = meeting.Location.DisplayName }); } return result; }
private static TimeSpan ParseTimeSlot(MeetingTimeSlot.TimeDescriptor dateTime) { var time = DateTime.Parse(dateTime.Time); time = DateTime.SpecifyKind(time, DateTimeKind.Utc); time = time.ToLocalTime(); return time.TimeOfDay; }