public IList <GoogleCalendarEventSyncData> GetSyncDataList() { bool isDefaultCalendarExist = false; var defaultCalendar = GetDefaultCalendar(_token, out isDefaultCalendarExist); DateTime startTime = DateTime.UtcNow.Date; DateTime endTime = startTime.AddMonths(GoogleSyncSettings.DefaultCalendarImportTimeMonths); bool isFromDefault = true; var listRequest = _calendarService.Events.List(defaultCalendar.Id); listRequest.MaxResults = GoogleSyncSettings.DefaultMaxCalendarEventCount; var evnts = listRequest.Fetch().Items; if (!isDefaultCalendarExist) { //默认的不存在,不从Google默认的日历读取任务 //evnts = _calendarService.Events.List("primary").Fetch().Items; isFromDefault = false; } List <GoogleCalendarEventSyncData> items = new List <GoogleCalendarEventSyncData>(); if (evnts != null && evnts.Count() > 0) { foreach (var evnt in evnts) { //这里目前没有找到可以根据开始日期和结束日期查询的接口, //只能查处所有当前日历的事件,然后在内存过滤 DateTime result; if (Rfc3339DateTime.TryParse(evnt.End.DateTime, out result)) { var end = result.ToLocalTime(); if (end >= startTime && end <= endTime) { var syncData = new GoogleCalendarEventSyncData(evnt); syncData.IsFromDefault = isFromDefault; items.Add(syncData); } } } } return(items); }
/// <summary> /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent. /// </summary> /// <param name="s">A string containing a date and time to convert.</param> /// <returns>A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>.</returns> /// <remarks> /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception> /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 3339 string representation of a date and time.</exception> public static DateTime Parse(string s) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ if (s == null) { throw new ArgumentNullException("s"); } DateTime result; if (Rfc3339DateTime.TryParse(s, out result)) { return(result); } else { throw new FormatException(String.Format(null, "{0} is not a valid RFC 3339 string representation of a date and time.", s)); } }