public async Task GetEventsByTimeTest() { ICalendar mockCalendarService = new MockCalendarService("test token"); IServiceManager serviceManager = new ServiceManager(new SkillConfiguration()); ICalendar calendarService = serviceManager.InitCalendarService(mockCalendarService, EventSource.Microsoft); await calendarService.GetEventsByTime(DateTime.SpecifyKind(new DateTime(), DateTimeKind.Utc), DateTime.SpecifyKind(new DateTime(), DateTimeKind.Utc)); }
public async Task GetEventsByTimeTest() { DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse("2500-01-01T18:00:00.0000000Z")); DateTime endTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse("2500-01-01T19:00:00.0000000Z")); List <EventModel> events = await CalendarService.GetEventsByTime(startTime, endTime); Assert.IsTrue(events.Count == 3); }
/// <inheritdoc/> public async Task <List <EventModel> > GetEventsByTime(DateTime startTime, DateTime endTime) { if (startTime.Kind != DateTimeKind.Utc) { throw new Exception("Get Event By Time - Start Time is not UTC"); } if (endTime.Kind != DateTimeKind.Utc) { throw new Exception("Get Event By Time - End Time is not UTC"); } return(await calendarAPI.GetEventsByTime(startTime, endTime)); }
protected async Task <List <EventModel> > GetEventsByTime(DateTime?startDate, DateTime?startTime, DateTime?endDate, DateTime?endTime, TimeZoneInfo userTimeZone, ICalendar calendarService) { // todo: check input datetime is utc var rawEvents = new List <EventModel>(); var resultEvents = new List <EventModel>(); bool searchByStartTime = startTime != null && endDate == null && endTime == null; startDate = startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); endDate = endDate ?? startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); var searchStartTime = startTime == null ? new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day) : new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, startTime.Value.Hour, startTime.Value.Minute, startTime.Value.Second); searchStartTime = TimeZoneInfo.ConvertTimeToUtc(searchStartTime, userTimeZone); var searchEndTime = endTime == null ? new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 23, 59, 59) : new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, endTime.Value.Hour, endTime.Value.Minute, endTime.Value.Second); searchEndTime = TimeZoneInfo.ConvertTimeToUtc(searchEndTime, userTimeZone); if (searchByStartTime) { rawEvents = await calendarService.GetEventsByStartTime(searchStartTime); } else { rawEvents = await calendarService.GetEventsByTime(searchStartTime, searchEndTime); } foreach (var item in rawEvents) { if (item.StartTime >= searchStartTime && item.IsCancelled != true) { resultEvents.Add(item); } } return(resultEvents); }
protected async Task <List <EventModel> > GetEventsByTime(List <DateTime> startDateList, List <DateTime> startTimeList, List <DateTime> endDateList, List <DateTime> endTimeList, TimeZoneInfo userTimeZone, ICalendar calendarService) { // todo: check input datetime is utc var rawEvents = new List <EventModel>(); var resultEvents = new List <EventModel>(); DateTime?startDate = null; if (startDateList.Any()) { startDate = startDateList.Last(); } DateTime?endDate = null; if (endDateList.Any()) { endDate = endDateList.Last(); } bool searchByStartTime = startTimeList.Any() && endDate == null && !endTimeList.Any(); startDate = startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); endDate = endDate ?? startDate ?? TimeConverter.ConvertUtcToUserTime(DateTime.UtcNow, userTimeZone); var searchStartTimeList = new List <DateTime>(); var searchEndTimeList = new List <DateTime>(); if (startTimeList.Any()) { foreach (var time in startTimeList) { searchStartTimeList.Add(TimeZoneInfo.ConvertTimeToUtc( new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, time.Hour, time.Minute, time.Second), userTimeZone)); } } else { searchStartTimeList.Add(TimeZoneInfo.ConvertTimeToUtc( new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day), userTimeZone)); } if (endTimeList.Any()) { foreach (var time in endTimeList) { searchEndTimeList.Add(TimeZoneInfo.ConvertTimeToUtc( new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, time.Hour, time.Minute, time.Second), userTimeZone)); } } else { searchEndTimeList.Add(TimeZoneInfo.ConvertTimeToUtc( new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 23, 59, 59), userTimeZone)); } DateTime?searchStartTime = null; if (searchByStartTime) { foreach (var startTime in searchStartTimeList) { rawEvents = await calendarService.GetEventsByStartTime(startTime); if (rawEvents.Any()) { searchStartTime = startTime; break; } } } else { for (var i = 0; i < searchStartTimeList.Count(); i++) { rawEvents = await calendarService.GetEventsByTime( searchStartTimeList[i], searchEndTimeList.Count() > i?searchEndTimeList[i] : searchEndTimeList[0]); if (rawEvents.Any()) { searchStartTime = searchStartTimeList[i]; break; } } } foreach (var item in rawEvents) { if (item.StartTime >= searchStartTime && item.IsCancelled != true) { resultEvents.Add(item); } } return(resultEvents); }
public async Task GetEventsByTimeTest() { await CalendarService.GetEventsByTime(DateTime.SpecifyKind(new DateTime(), DateTimeKind.Utc), DateTime.SpecifyKind(new DateTime(), DateTimeKind.Utc)); }
/// <inheritdoc/> public async Task <List <EventModel> > GetEventsByTime(DateTime startTime, DateTime endTime) { return(await calendarAPI.GetEventsByTime(startTime, endTime)); }