Files
chapter-organizer/tools/GoogleSheetsScheduleImport/OccurrenceChronologicalSort.cs
poprhythm f400813667 Update EventOccurrence parsing to use EventOccurrenceParseGroup for improved data structure
This commit refactors the EventOccurrence parsing logic to utilize the EventOccurrenceParseGroup class, enhancing the organization of parsed occurrences by grouping them based on event definitions and optional section levels. The changes include updates to the EventOccurrenceParseResult, EventOccurrenceParser, and EventOccurrenceParserService to accommodate the new grouping structure. Additionally, tests are modified to reflect these changes, ensuring that the parsing functionality remains intact and accurate. This refactor improves data handling and aligns with the overall architecture of the application.
2026-04-04 21:55:44 -04:00

32 lines
850 B
C#

using Core.Parsers.EventOccurrence;
using Core.Utility;
namespace GoogleSheetsScheduleImport;
public static class OccurrenceChronologicalSort
{
public static List<ParsedOccurrenceLine> Sort(IEnumerable<ParsedOccurrenceLine> 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;
}
}
}