better class day highlighting

This commit is contained in:
2023-01-18 21:12:13 -07:00
parent 4a321ffa4a
commit 4da93ca348
13 changed files with 84 additions and 111 deletions

View File

@@ -2,23 +2,26 @@ using CanvasModel.EnrollmentTerms;
public class SemesterPlanner
{
public DateTime FirstDay { get; }
public DateTime LastDay { get; }
public IEnumerable<CalendarMonth> Months { get; }
public IEnumerable<DayOfWeek> Days { get; }
public SemesterPlanner(SemesterConfiguration configuration)
{
var start = configuration.StartDate;
var end = configuration.EndDate;
FirstDay = configuration.StartDate;
LastDay = configuration.EndDate;
var monthsInTerm =
1 + ((end.Year - start.Year) * 12)
+ end.Month - start.Month;
1 + ((LastDay.Year - FirstDay.Year) * 12)
+ LastDay.Month - FirstDay.Month;
Months = Enumerable
.Range(0, monthsInTerm)
.Select(monthDiff =>
{
var month = ((start.Month + monthDiff - 1) % 12) + 1;
var year = start.Year + ((start.Month + monthDiff - 1) / 12);
var month = ((FirstDay.Month + monthDiff - 1) % 12) + 1;
var year = FirstDay.Year + ((FirstDay.Month + monthDiff - 1) / 12);
return new CalendarMonth(year, month);
});
Days = configuration.Days;

View File

@@ -1,8 +1,8 @@
using CanvasModel.EnrollmentTerms;
public class ConfigurationManagement
public class ConfigurationManagement : IConfigurationManagement
{
public static SemesterConfiguration CreateFromTerm(
public void SetConfiguration(
EnrollmentTermModel canvasTerm,
DayOfWeek[] daysOfWeek
)
@@ -10,10 +10,15 @@ public class ConfigurationManagement
var start = canvasTerm.StartAt ?? throw new Exception($"Canvas Term must have a start date. Term: {canvasTerm.Name}");
var end = canvasTerm.EndAt ?? throw new Exception($"Canvas Term must have a end date. Term: {canvasTerm.Name}");
return new SemesterConfiguration(
Configuration = new SemesterConfiguration(
StartDate: start,
EndDate: end,
Days: daysOfWeek
);
}
public SemesterConfiguration? Configuration { get; private set; } = null;
}

View File

@@ -0,0 +1,8 @@
using CanvasModel.EnrollmentTerms;
public interface IConfigurationManagement
{
SemesterConfiguration? Configuration { get; }
void SetConfiguration(EnrollmentTermModel canvasTerm, DayOfWeek[] daysOfWeek);
}