using Core.Parsers.EventOccurrence; using Core.Utility; namespace GoogleSheetsScheduleImport; public static class OccurrenceChronologicalSort { public static List Sort(IEnumerable lines, int year) { return lines .OrderBy(l => Key(l, year)) .ThenBy(l => l.SourceRowStart) .ThenBy(l => l.SourceCol) .ToList(); } private static DateTime Key(ParsedOccurrenceLine line, int year) { try { var d = TextUtil.ParseDate(line.Month, line.Day.ToString(), year); var timePart = TimeParser.ExtractStartTime(line.TimeRange); var t = TimeParser.Parse(timePart); return new DateTime(d, t); } catch { return DateTime.MaxValue; } } }