public void SetFeedInfoTest() { // create the feed. var feed = new GTFSFeed(); // create the feed info var info = new FeedInfo { StartDate = "some start date", EndDate = "some end date", Lang = "some language", PublisherName = "some publisher", PublisherUrl = "some url", Tag = new object(), Version = "some version" }; // verify initial state. var emptyFeedInfo = new FeedInfo(); var oldFeedInfo = feed.GetFeedInfo(); Assert.IsTrue(_comparer.Equals(emptyFeedInfo, oldFeedInfo)); // set the feed info. feed.SetFeedInfo(info); // test result. var newFeedInfo = feed.GetFeedInfo(); Assert.IsTrue(_comparer.Equals(info, newFeedInfo)); }
public static Tuple <DateTime, DateTime> GetFeedDateRange(GTFSFeed feed) { FeedInfo info = feed.GetFeedInfo(); if (info.StartDate != null && info.EndDate != null) { return(new Tuple <DateTime, DateTime>( DateTime.ParseExact(info.StartDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture), DateTime.ParseExact(info.EndDate, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture))); } DateTime?minStartLeft = null; DateTime?minStartRight = null; DateTime?maxEndLeft = null; DateTime?maxEndRight = null; DateTime minStart; DateTime maxEnd; if (feed.Calendars.Any()) { minStartLeft = feed.Calendars.Min(x => x.StartDate); maxEndLeft = feed.Calendars.Max(x => x.EndDate); } if (feed.CalendarDates.Any()) { minStartRight = feed.CalendarDates.Where(x => x.ExceptionType == ExceptionType.Added).Min(x => x.Date); maxEndRight = feed.CalendarDates.Where(x => x.ExceptionType == ExceptionType.Added).Max(x => x.Date); } if (minStartLeft.HasValue && minStartRight.HasValue) { if (minStartLeft > minStartRight) { minStart = minStartRight.Value; } else { minStart = minStartLeft.Value; } } else { if (minStartLeft.HasValue) { minStart = minStartLeft.Value; } else { minStart = minStartRight.Value; } } if (maxEndLeft.HasValue && maxEndRight.HasValue) { if (maxEndLeft > maxEndRight) { maxEnd = maxEndLeft.Value; } else { maxEnd = maxEndLeft.Value; } } else { if (maxEndLeft.HasValue) { maxEnd = maxEndLeft.Value; } else { maxEnd = maxEndRight.Value; } } return(new Tuple <DateTime, DateTime>(minStart, maxEnd)); }