47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using GmRelay.Shared.Domain;
|
|
|
|
namespace GmRelay.Web.Services;
|
|
|
|
public enum BatchCloneInterval
|
|
{
|
|
NextWeek,
|
|
NextMonth
|
|
}
|
|
|
|
public sealed record WebSessionBatch(
|
|
Guid Id,
|
|
Guid GroupId,
|
|
string Title,
|
|
string JoinLink,
|
|
DateTime FirstScheduledAt,
|
|
DateTime LastScheduledAt,
|
|
int SessionCount,
|
|
string NotificationMode = SessionNotificationModeExtensions.GroupAndDirectValue);
|
|
|
|
public static class BatchSchedulePlanner
|
|
{
|
|
public static IReadOnlyList<DateTime> BuildFixedIntervalSchedule(
|
|
IEnumerable<DateTime> currentSchedule,
|
|
DateTime firstScheduledAt,
|
|
int intervalDays)
|
|
{
|
|
if (intervalDays <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(intervalDays), intervalDays, "Interval must be greater than zero.");
|
|
}
|
|
|
|
return currentSchedule
|
|
.OrderBy(scheduledAt => scheduledAt)
|
|
.Select((_, index) => firstScheduledAt.AddDays(intervalDays * index))
|
|
.ToList();
|
|
}
|
|
|
|
public static DateTime ShiftForClone(DateTime scheduledAt, BatchCloneInterval interval) =>
|
|
interval switch
|
|
{
|
|
BatchCloneInterval.NextWeek => scheduledAt.AddDays(7),
|
|
BatchCloneInterval.NextMonth => scheduledAt.AddMonths(1),
|
|
_ => throw new ArgumentOutOfRangeException(nameof(interval), interval, "Unknown clone interval.")
|
|
};
|
|
}
|