using System; namespace PKHeX.Core; /// /// Record to store the date range availability for a distribution. /// /// Absolute earliest date the distribution can be received. /// Absolute latest date the distribution can be received. /// Days after the earliest start date that a distribution would normally be generated with. public readonly record struct DistributionWindow(DateOnly Start, DateOnly? End = null, byte GenerateDaysAfterStart = 0) { public DistributionWindow(int startYear, int startMonth, int startDay, byte generateDaysAfterStart = 0) : this(new DateOnly(startYear, startMonth, startDay), null, generateDaysAfterStart) { } public DistributionWindow(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay, byte generateDaysAfterStart = 0) : this(new DateOnly(startYear, startMonth, startDay), new DateOnly(endYear, endMonth, endDay), generateDaysAfterStart) { } /// /// Checks if the date obtained is within the date of availability for the given range. /// /// Date obtained. /// True if the date obtained is within the date of availability for the given range. public bool Contains(DateOnly obtained) => Start <= obtained && !(obtained > End); /// /// Get a valid date within the generation range. /// public DateOnly GetGenerateDate() => Start.AddDays(GenerateDaysAfterStart); /// /// Checks if the distribution was acquired earlier than generally available. /// /// Date obtained. /// Only relevant when is non-zero. public bool IsEarlyAcquisition(DateOnly obtained) => obtained < Start.AddDays(GenerateDaysAfterStart); /// /// Checks if the distribution can be acquired earlier than generally available. /// public bool CanAcquireEarly => GenerateDaysAfterStart > 0; }