PKHeX/PKHeX.Core/Legality/Encounters/Data/Live/DistributionWindow.cs
Kurt fd1c538cc5
Changes for Legends: Z-A support (#4596)
Refer to pull request notes and the eventual changelog for a high-level summary.

Co-authored-by: Matt <17801814+sora10pls@users.noreply.github.com>
Co-authored-by: Lusamine <30205550+Lusamine@users.noreply.github.com>
Co-authored-by: SciresM <8676005+SciresM@users.noreply.github.com>
2025-10-26 19:01:44 -05:00

43 lines
2.1 KiB
C#

using System;
namespace PKHeX.Core;
/// <summary>
/// Record to store the date range availability for a distribution.
/// </summary>
/// <param name="Start">Absolute earliest date the distribution can be received.</param>
/// <param name="End">Absolute latest date the distribution can be received.</param>
/// <param name="GenerateDaysAfterStart">Days after the earliest start date that a distribution would normally be generated with.</param>
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) { }
/// <summary>
/// Checks if the date obtained is within the date of availability for the given range.
/// </summary>
/// <param name="obtained">Date obtained.</param>
/// <returns>True if the date obtained is within the date of availability for the given range.</returns>
public bool Contains(DateOnly obtained) => Start <= obtained && !(obtained > End);
/// <summary>
/// Get a valid date within the generation range.
/// </summary>
public DateOnly GetGenerateDate() => Start.AddDays(GenerateDaysAfterStart);
/// <summary>
/// Checks if the distribution was acquired earlier than generally available.
/// </summary>
/// <param name="obtained">Date obtained.</param>
/// <remarks>Only relevant when <see cref="GenerateDaysAfterStart"/> is non-zero.</remarks>
public bool IsEarlyAcquisition(DateOnly obtained) => obtained < Start.AddDays(GenerateDaysAfterStart);
/// <summary>
/// Checks if the distribution can be acquired earlier than generally available.
/// </summary>
public bool CanAcquireEarly => GenerateDaysAfterStart > 0;
}