diff --git a/PKHeX.Core/Editing/Applicators/PersonalColorUtil.cs b/PKHeX.Core/Editing/Applicators/PersonalColorUtil.cs index 06ed24934..fecdbf716 100644 --- a/PKHeX.Core/Editing/Applicators/PersonalColorUtil.cs +++ b/PKHeX.Core/Editing/Applicators/PersonalColorUtil.cs @@ -27,9 +27,9 @@ public static PersonalColor GetColor(IEncounterTemplate enc) public static ReadOnlySpan GetPreferredByColor(IEncounterTemplate enc) => GetPreferredByColor(enc, GetColor(enc)); - public static ReadOnlySpan GetPreferredByColor(T enc, PersonalColor color) where T : IVersion + public static ReadOnlySpan GetPreferredByColor(T enc, PersonalColor color) where T : IContext { - if (enc.Version is GameVersion.PLA) + if (enc.Context is EntityContext.Gen8a) return GetPreferredByColorLA(color); return GetPreferredByColor(color); } diff --git a/PKHeX.Core/Game/Enums/LanguageBR.cs b/PKHeX.Core/Game/Enums/LanguageBR.cs index e6bd6867a..ed07e8f89 100644 --- a/PKHeX.Core/Game/Enums/LanguageBR.cs +++ b/PKHeX.Core/Game/Enums/LanguageBR.cs @@ -1,7 +1,7 @@ namespace PKHeX.Core; /// -/// Game Language IDs +/// Game Language IDs /// public enum LanguageBR : byte { diff --git a/PKHeX.Core/Legality/Encounters/Data/Live/EncounterServerDate.cs b/PKHeX.Core/Legality/Encounters/Data/Live/EncounterServerDate.cs index a7ba4ed51..6d024fa06 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Live/EncounterServerDate.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Live/EncounterServerDate.cs @@ -24,6 +24,7 @@ public static class EncounterServerDate WA8 wa8 => Result(wa8.IsWithinDistributionWindow(obtained)), WB8 wb8 => Result(wb8.IsWithinDistributionWindow(obtained)), WC9 wc9 => Result(wc9.IsWithinDistributionWindow(obtained)), + EncounterSlot7GO g7 => Result(g7.IsWithinDistributionWindow(obtained)), EncounterSlot8GO g8 => Result(g8.IsWithinDistributionWindow(obtained)), _ => throw new ArgumentOutOfRangeException(nameof(enc)), }; diff --git a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs index 90daa6285..34ddd154e 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/GO/EncounterSlot7GO.cs @@ -7,8 +7,9 @@ namespace PKHeX.Core; /// /// public sealed record EncounterSlot7GO(int StartDate, int EndDate, ushort Species, byte Form, byte LevelMin, byte LevelMax, Shiny Shiny, Gender Gender, PogoType Type) - : IEncounterable, IEncounterMatch, IPogoSlot, IEncounterConvertible + : IEncounterable, IEncounterMatch, IPogoSlot, IEncounterConvertible, IEncounterServerDate { + public bool IsDateRestricted => true; public byte Generation => 7; public EntityContext Context => EntityContext.Gen7b; public Ball FixedBall => Ball.None; // GO Park can override the ball; obey capture rules for LGP/E @@ -137,6 +138,18 @@ public bool IsMatchExact(PKM pk, EvoCriteria evo) return true; } + public bool IsWithinDistributionWindow(PKM pk) + { + var date = new DateOnly(pk.MetYear + 2000, pk.MetMonth, pk.MetDay); + return IsWithinDistributionWindow(date); + } + + public bool IsWithinDistributionWindow(DateOnly date) + { + var stamp = PogoDateRangeExtensions.GetTimeStamp(date.Year, date.Month, date.Day); + return this.IsWithinStartEnd(stamp); + } + public EncounterMatchRating GetMatchRating(PKM pk) { var stamp = PogoDateRangeExtensions.GetTimeStamp(pk.MetYear + 2000, pk.MetMonth, pk.MetDay); diff --git a/PKHeX.Core/Legality/Encounters/Templates/Interfaces/IEncounterTemplate.cs b/PKHeX.Core/Legality/Encounters/Templates/Interfaces/IEncounterTemplate.cs index 6dc466b43..5e6fb993b 100644 --- a/PKHeX.Core/Legality/Encounters/Templates/Interfaces/IEncounterTemplate.cs +++ b/PKHeX.Core/Legality/Encounters/Templates/Interfaces/IEncounterTemplate.cs @@ -3,13 +3,8 @@ namespace PKHeX.Core; /// /// Represents all details that an entity may be encountered with. /// -public interface IEncounterTemplate : ISpeciesForm, IVersion, IGeneration, IShiny, ILevelRange, ILocation, IFixedAbilityNumber, IFixedBall, IShinyPotential +public interface IEncounterTemplate : ISpeciesForm, IVersion, IGeneration, IShiny, ILevelRange, ILocation, IFixedAbilityNumber, IFixedBall, IShinyPotential, IContext { - /// - /// Original Context - /// - EntityContext Context { get; } - /// /// Indicates if the encounter originated as an egg. /// diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index 7fe9570da..5949db023 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -79,18 +79,18 @@ public override void Verify(LegalityAnalysis data) VerifyFullness(data, pk); var enc = data.EncounterMatch; - if (enc is IEncounterServerDate { IsDateRestricted: true } serverGift) + if (enc is IEncounterServerDate { IsDateRestricted: true } encounterDate) { - var date = new DateOnly(pk.MetYear + 2000, pk.MetMonth, pk.MetDay); + var actualDay = new DateOnly(pk.MetYear + 2000, pk.MetMonth, pk.MetDay); // HOME Gifts for Sinnoh/Hisui starters were forced JPN until May 20, 2022 (UTC). if (enc is WB8 { IsDateLockJapanese: true } or WA8 { IsDateLockJapanese: true }) { - if (date < new DateOnly(2022, 5, 20) && pk.Language != (int)LanguageID.Japanese) + if (actualDay < new DateOnly(2022, 5, 20) && pk.Language != (int)LanguageID.Japanese) data.AddLine(GetInvalid(LDateOutsideDistributionWindow)); } - var result = serverGift.IsWithinDistributionWindow(date); + var result = encounterDate.IsWithinDistributionWindow(actualDay); if (result == EncounterServerDateCheck.Invalid) data.AddLine(GetInvalid(LDateOutsideDistributionWindow)); } diff --git a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonRules.cs b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonRules.cs index b5f5cf792..8c3f286e3 100644 --- a/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonRules.cs +++ b/PKHeX.Core/Legality/Verifiers/Ribbons/RibbonRules.cs @@ -106,11 +106,11 @@ public static bool IsRibbonValidMasterRank(PKM pk, IEncounterTemplate enc, Evolu private static bool IsRibbonValidMasterRankSWSH(PKM pk, IEncounterTemplate enc) { // Transfers from prior games, as well as from GO, require the battle-ready symbol in order to participate in Ranked. - if ((enc.Generation < 8 || enc.Version == GameVersion.GO) && pk is IBattleVersion { BattleVersion: 0 }) + if ((enc.Generation < 8 || enc.Context is EntityContext.Gen7b) && pk is IBattleVersion { BattleVersion: 0 }) return false; - // GO transfers: Capture date is global time, and not console changeable. - bool hasRealDate = enc.Version == GameVersion.GO || enc is IEncounterServerDate { IsDateRestricted: true }; + // GO transfers and server gifts: Capture date is global time, and not console changeable. + bool hasRealDate = enc is IEncounterServerDate { IsDateRestricted: true }; if (hasRealDate) { // Ranked is still ongoing, but the use of Mythicals was restricted to Series 13 only. diff --git a/PKHeX.Core/MysteryGifts/PGF.cs b/PKHeX.Core/MysteryGifts/PGF.cs index 7972638e3..6acdfd07c 100644 --- a/PKHeX.Core/MysteryGifts/PGF.cs +++ b/PKHeX.Core/MysteryGifts/PGF.cs @@ -122,7 +122,7 @@ public override string CardTitle get { // Check to see if date is valid - if (!DateUtil.IsDateValid(Year, Month, Day)) + if (!DateUtil.IsValidDate(Year, Month, Day)) return null; return new DateOnly(Year, Month, Day); diff --git a/PKHeX.Core/MysteryGifts/WB7.cs b/PKHeX.Core/MysteryGifts/WB7.cs index 70b4b20d1..0a6759bcd 100644 --- a/PKHeX.Core/MysteryGifts/WB7.cs +++ b/PKHeX.Core/MysteryGifts/WB7.cs @@ -83,7 +83,7 @@ private uint Day get { // Check to see if date is valid - if (!DateUtil.IsDateValid(Year, Month, Day)) + if (!DateUtil.IsValidDate(Year, Month, Day)) return null; return new DateOnly((int)Year, (int)Month, (int)Day); diff --git a/PKHeX.Core/MysteryGifts/WC6.cs b/PKHeX.Core/MysteryGifts/WC6.cs index db4988c8b..c131815dc 100644 --- a/PKHeX.Core/MysteryGifts/WC6.cs +++ b/PKHeX.Core/MysteryGifts/WC6.cs @@ -80,7 +80,7 @@ private uint Day get { // Check to see if date is valid - if (!DateUtil.IsDateValid(Year, Month, Day)) + if (!DateUtil.IsValidDate(Year, Month, Day)) return null; return new DateOnly((int)Year, (int)Month, (int)Day); diff --git a/PKHeX.Core/MysteryGifts/WC7.cs b/PKHeX.Core/MysteryGifts/WC7.cs index b170aa439..633c33625 100644 --- a/PKHeX.Core/MysteryGifts/WC7.cs +++ b/PKHeX.Core/MysteryGifts/WC7.cs @@ -80,7 +80,7 @@ private uint Day get { // Check to see if date is valid - if (!DateUtil.IsDateValid(Year, Month, Day)) + if (!DateUtil.IsValidDate(Year, Month, Day)) return null; return new DateOnly((int)Year, (int)Month, (int)Day); diff --git a/PKHeX.Core/PKM/Interfaces/Metadata/IContext.cs b/PKHeX.Core/PKM/Interfaces/Metadata/IContext.cs new file mode 100644 index 000000000..be4c6f149 --- /dev/null +++ b/PKHeX.Core/PKM/Interfaces/Metadata/IContext.cs @@ -0,0 +1,9 @@ +namespace PKHeX.Core; + +public interface IContext +{ + /// + /// The Context the data originated in. + /// + EntityContext Context { get; } +} diff --git a/PKHeX.Core/PKM/PB7.cs b/PKHeX.Core/PKM/PB7.cs index 124eb7a1c..880ca2ce1 100644 --- a/PKHeX.Core/PKM/PB7.cs +++ b/PKHeX.Core/PKM/PB7.cs @@ -342,7 +342,7 @@ public override string OriginalTrainerName { get { - if (!DateUtil.IsDateValid(2000 + ReceivedYear, ReceivedMonth, ReceivedDay)) + if (!DateUtil.IsValidDate(2000 + ReceivedYear, ReceivedMonth, ReceivedDay)) return null; return new DateOnly(ReceivedYear + 2000, ReceivedMonth, ReceivedDay); } @@ -370,7 +370,7 @@ public override string OriginalTrainerName { get { - if (!DateUtil.IsTimeValid(ReceivedHour, ReceivedMinute, ReceivedSecond)) + if (!DateUtil.IsValidTime(ReceivedHour, ReceivedMinute, ReceivedSecond)) return null; return new TimeOnly(ReceivedHour, ReceivedMinute, ReceivedSecond); } diff --git a/PKHeX.Core/PKM/PKM.cs b/PKHeX.Core/PKM/PKM.cs index 57555e1b7..be2e82490 100644 --- a/PKHeX.Core/PKM/PKM.cs +++ b/PKHeX.Core/PKM/PKM.cs @@ -164,7 +164,7 @@ private byte[] Write() get { // Check to see if date is valid - if (!DateUtil.IsDateValid(2000 + MetYear, MetMonth, MetDay)) + if (!DateUtil.IsValidDate(2000 + MetYear, MetMonth, MetDay)) return null; return new DateOnly(2000 + MetYear, MetMonth, MetDay); } @@ -207,7 +207,7 @@ private byte[] Write() get { // Check to see if date is valid - if (!DateUtil.IsDateValid(2000 + EggYear, EggMonth, EggDay)) + if (!DateUtil.IsValidDate(2000 + EggYear, EggMonth, EggDay)) return null; return new DateOnly(2000 + EggYear, EggMonth, EggDay); } diff --git a/PKHeX.Core/PKM/Util/EntityDetection.cs b/PKHeX.Core/PKM/Util/EntityDetection.cs index cb7f9ba55..51fc060e5 100644 --- a/PKHeX.Core/PKM/Util/EntityDetection.cs +++ b/PKHeX.Core/PKM/Util/EntityDetection.cs @@ -4,6 +4,9 @@ namespace PKHeX.Core; +/// +/// Logic for detecting a entity from a byte array or length. +/// public static class EntityDetection { /// diff --git a/PKHeX.Core/PKM/Util/EntityFileExtension.cs b/PKHeX.Core/PKM/Util/EntityFileExtension.cs index 8d026801f..715bdb207 100644 --- a/PKHeX.Core/PKM/Util/EntityFileExtension.cs +++ b/PKHeX.Core/PKM/Util/EntityFileExtension.cs @@ -3,6 +3,9 @@ namespace PKHeX.Core; +/// +/// Logic for interacting with Entity file extensions. +/// public static class EntityFileExtension { // All side-game formats that don't follow the usual pk* format diff --git a/PKHeX.Core/PKM/Util/EntityFileNamer.cs b/PKHeX.Core/PKM/Util/EntityFileNamer.cs index caa71d5d2..7704ab697 100644 --- a/PKHeX.Core/PKM/Util/EntityFileNamer.cs +++ b/PKHeX.Core/PKM/Util/EntityFileNamer.cs @@ -4,6 +4,9 @@ namespace PKHeX.Core; +/// +/// Logic for creating file names for data. +/// public static class EntityFileNamer { /// diff --git a/PKHeX.Core/PKM/Util/EntityFormat.cs b/PKHeX.Core/PKM/Util/EntityFormat.cs index 3e1dc09c6..4e42c0b78 100644 --- a/PKHeX.Core/PKM/Util/EntityFormat.cs +++ b/PKHeX.Core/PKM/Util/EntityFormat.cs @@ -5,6 +5,9 @@ namespace PKHeX.Core; +/// +/// Utility class for detecting the type format of a Pokémon entity. +/// public static class EntityFormat { /// @@ -210,7 +213,7 @@ private static EntityFormatDetected IsFormatReally8b(PK8 pk) public enum EntityFormatDetected { - None = -1, + None, FormatPK1, FormatPK2, FormatSK2, diff --git a/PKHeX.Core/PKM/Util/EntityPID.cs b/PKHeX.Core/PKM/Util/EntityPID.cs index 2b2b03e2d..b11acf3be 100644 --- a/PKHeX.Core/PKM/Util/EntityPID.cs +++ b/PKHeX.Core/PKM/Util/EntityPID.cs @@ -2,6 +2,9 @@ namespace PKHeX.Core; +/// +/// Logic for creating a PID, mostly for originating in Generations 3-5. +/// public static class EntityPID { /// @@ -25,7 +28,7 @@ public static uint GetRandomPID(Random rnd, ushort species, byte gender, GameVer // Below logic handles Gen3-5. // No need to get form specific entry, as Gen3-5 do not have that feature. var gt = PersonalTable.B2W2[species].Gender; - bool g34 = origin <= GameVersion.CXD; + bool g34 = origin.IsGen3(); uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000; bool g3unown = origin is GameVersion.FR or GameVersion.LG && species == (int)Species.Unown; diff --git a/PKHeX.Core/PKM/Util/RecentTrainerCache.cs b/PKHeX.Core/PKM/Util/RecentTrainerCache.cs index 8e0eaed0f..301c18ca0 100644 --- a/PKHeX.Core/PKM/Util/RecentTrainerCache.cs +++ b/PKHeX.Core/PKM/Util/RecentTrainerCache.cs @@ -36,6 +36,8 @@ public static class RecentTrainerCache public static void SetRecentTrainer(ITrainerInfo trainer) { Trainer = trainer; + + // Update Gen6/7 trainer reference if applicable, otherwise retain whatever was there. if (trainer is IRegionOriginReadOnly g67) Trainer67 = g67; } diff --git a/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs b/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs index 854b28810..7bd15ed7d 100644 --- a/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs +++ b/PKHeX.Core/Saves/Abstractions/SimpleTrainerInfo.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; /// /// Simple record containing trainer data /// -public sealed record SimpleTrainerInfo : ITrainerInfo, IRegionOriginReadOnly +public sealed record SimpleTrainerInfo : ITrainerInfo, IRegionOriginReadOnly, ITrainerID { public string OT { get; init; } = TrainerName.ProgramINT; public ushort TID16 { get; init; } = 12345; diff --git a/PKHeX.Core/Saves/SAV4BR.cs b/PKHeX.Core/Saves/SAV4BR.cs index 13264ec9d..ab8b081fc 100644 --- a/PKHeX.Core/Saves/SAV4BR.cs +++ b/PKHeX.Core/Saves/SAV4BR.cs @@ -165,7 +165,8 @@ private static bool IsChecksumValid(Span sav, int offset) public override int Language { get => (int)(BRLanguage == LanguageBR.JapaneseOrEnglish && Japanese ? LanguageID.Japanese : BRLanguage.ToLanguageID()); - set { + set + { Japanese = value == (int)LanguageID.Japanese; BRLanguage = ((LanguageID)value).ToLanguageBR(); } diff --git a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo6.cs b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo6.cs index c2e946691..305330572 100644 --- a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo6.cs +++ b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo6.cs @@ -137,7 +137,7 @@ public void SetTeam(IReadOnlyList team, int t) { get { - if (!DateUtil.IsDateValid(MatchYear, MatchMonth, MatchDay)) + if (!DateUtil.IsValidDate(MatchYear, MatchMonth, MatchDay)) return null; return new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond); } @@ -163,7 +163,7 @@ public void SetTeam(IReadOnlyList team, int t) { get { - if (!DateUtil.IsDateValid(UploadYear, UploadMonth, UploadDay)) + if (!DateUtil.IsValidDate(UploadYear, UploadMonth, UploadDay)) return null; return new DateTime(UploadYear, UploadMonth, UploadDay, UploadHour, UploadMinute, UploadSecond); } diff --git a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo7.cs b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo7.cs index d7f363363..d1e1bc7f6 100644 --- a/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo7.cs +++ b/PKHeX.Core/Saves/Substructures/Battle Videos/BattleVideo7.cs @@ -95,7 +95,7 @@ public void SetPlayerNames(IReadOnlyList value) { get { - if (!DateUtil.IsDateValid(MatchYear, MatchMonth, MatchDay)) + if (!DateUtil.IsValidDate(MatchYear, MatchMonth, MatchDay)) return null; return new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond); } diff --git a/PKHeX.Core/Saves/Substructures/Gen6/PlayTime6.cs b/PKHeX.Core/Saves/Substructures/Gen6/PlayTime6.cs index db85e8f25..55b05f0dd 100644 --- a/PKHeX.Core/Saves/Substructures/Gen6/PlayTime6.cs +++ b/PKHeX.Core/Saves/Substructures/Gen6/PlayTime6.cs @@ -44,7 +44,7 @@ public abstract class PlayTimeLastSaved(TSave sav, Memory r public DateTime? LastSavedDate { - get => !DateUtil.IsDateValid(LastSaved.Year, LastSaved.Month, LastSaved.Day) + get => !DateUtil.IsValidDate(LastSaved.Year, LastSaved.Month, LastSaved.Day) ? null : LastSaved.Timestamp; set diff --git a/PKHeX.Core/Saves/Substructures/Gen7/JoinFesta7.cs b/PKHeX.Core/Saves/Substructures/Gen7/JoinFesta7.cs index 9934823eb..8e167842f 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/JoinFesta7.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/JoinFesta7.cs @@ -73,7 +73,7 @@ public void SetFestaPhraseUnlocked(int index, bool value) public DateTime? FestaDate { - get => FestaYear >= 0 && FestaMonth > 0 && FestaDay > 0 && FestaHour >= 0 && FestaMinute >= 0 && FestaSecond >= 0 && DateUtil.IsDateValid(FestaYear, FestaMonth, FestaDay) + get => FestaYear >= 0 && FestaMonth > 0 && FestaDay > 0 && FestaHour >= 0 && FestaMinute >= 0 && FestaSecond >= 0 && DateUtil.IsValidDate(FestaYear, FestaMonth, FestaDay) ? new DateTime(FestaYear, FestaMonth, FestaDay, FestaHour, FestaMinute, FestaSecond) : null; set diff --git a/PKHeX.Core/Util/DateUtil.cs b/PKHeX.Core/Util/DateUtil.cs index 616a50fe4..51fcd8107 100644 --- a/PKHeX.Core/Util/DateUtil.cs +++ b/PKHeX.Core/Util/DateUtil.cs @@ -11,7 +11,7 @@ public static class DateUtil /// The month of the date of which to check the validity. /// The day of the date of which to check the validity. /// A boolean indicating if the date is valid. - public static bool IsDateValid(int year, int month, int day) + public static bool IsValidDate(int year, int month, int day) { if (year is <= 0 or > 9999) return false; @@ -30,14 +30,20 @@ public static bool IsDateValid(int year, int month, int day) /// The month of the date of which to check the validity. /// The day of the date of which to check the validity. /// A boolean indicating if the date is valid. - public static bool IsDateValid(uint year, uint month, uint day) + public static bool IsValidDate(uint year, uint month, uint day) { - return year < int.MaxValue && month < int.MaxValue && day < int.MaxValue && IsDateValid((int)year, (int)month, (int)day); + return year < int.MaxValue && month < int.MaxValue && day < int.MaxValue && IsValidDate((int)year, (int)month, (int)day); } private static readonly DateTime Epoch2000 = new(2000, 1, 1); private const int SecondsPerDay = 60*60*24; // 86400 + /// + /// Combines the date and time components into a seconds-elapsed value, relative to the epoch 2000. + /// + /// Date component + /// Time component + /// Seconds elapsed since epoch 2000 public static int GetSecondsFrom2000(DateTime date, DateTime time) { int seconds = (int)(date - Epoch2000).TotalSeconds; @@ -46,12 +52,24 @@ public static int GetSecondsFrom2000(DateTime date, DateTime time) return seconds; } + /// + /// Converts a seconds-elapsed value to the Date and Time components, relative to the epoch 2000. + /// + /// Seconds elapsed since epoch 2000 + /// Date component + /// Time component public static void GetDateTime2000(uint seconds, out DateTime date, out DateTime time) { date = Epoch2000.AddSeconds(seconds); time = Epoch2000.AddSeconds(seconds % SecondsPerDay); } + /// + /// Converts a seconds-elapsed value to a string. + /// + /// Seconds elapsed + /// If provided, treat as epoch 2000 + secondsBias + /// String representation of the date/time value public static string ConvertDateValueToString(int value, int secondsBias = -1) { var sb = new System.Text.StringBuilder(); @@ -81,7 +99,14 @@ public static DateOnly GetRandomDateWithin(DateOnly start, DateOnly end, Random /// public static DateOnly GetRandomDateWithin(DateOnly start, DateOnly end) => GetRandomDateWithin(start, end, Util.Rand); - public static bool IsTimeValid(byte receivedHour, byte receivedMinute, byte receivedSecond) + /// + /// Checks if the given time components represent a valid time. + /// + /// + /// + /// + /// + public static bool IsValidTime(byte receivedHour, byte receivedMinute, byte receivedSecond) { return receivedHour < 24u && receivedMinute < 60u && receivedSecond < 60u; } diff --git a/PKHeX.Core/Util/Util.cs b/PKHeX.Core/Util/Util.cs index b1801db45..d3d1e19e3 100644 --- a/PKHeX.Core/Util/Util.cs +++ b/PKHeX.Core/Util/Util.cs @@ -179,7 +179,6 @@ public static string ToTitleCase(ReadOnlySpan span) /// public static void ToTitleCase(ReadOnlySpan span, Span result) { - // Add each word to the string builder. Continue from the first index that isn't a space. // Add the first character as uppercase, then add each successive character as lowercase. bool first = true; for (var i = 0; i < span.Length; i++) diff --git a/Tests/PKHeX.Core.Tests/Util/DateUtilTests.cs b/Tests/PKHeX.Core.Tests/Util/DateUtilTests.cs index 4f7d5a5a7..e08a84746 100644 --- a/Tests/PKHeX.Core.Tests/Util/DateUtilTests.cs +++ b/Tests/PKHeX.Core.Tests/Util/DateUtilTests.cs @@ -11,7 +11,7 @@ public class DateUtilTests [InlineData(2001, 1, 31)] public void RecognizesCorrectDates(int year, int month, int day) { - Assert.True(DateUtil.IsDateValid(year, month, day), $"Failed to recognize {year}/{month}/{day}"); + Assert.True(DateUtil.IsValidDate(year, month, day), $"Failed to recognize {year}/{month}/{day}"); } [Theory] @@ -29,13 +29,13 @@ public void RecognizesCorrectDates(int year, int month, int day) [InlineData(2016, 12, 31)] public void RecognizesValidMonthBoundaries(int year, int month, int day) { - Assert.True(DateUtil.IsDateValid(year, month, day), $"Incorrect month boundary for {year}/{month}/{day}"); + Assert.True(DateUtil.IsValidDate(year, month, day), $"Incorrect month boundary for {year}/{month}/{day}"); } [Fact] public void RecognizeCorrectLeapYear() { - Assert.True(DateUtil.IsDateValid(2004, 2, 29)); + Assert.True(DateUtil.IsValidDate(2004, 2, 29)); } [Theory] @@ -51,7 +51,7 @@ public void RecognizeCorrectLeapYear() [InlineData(uint.MaxValue, uint.MaxValue, uint.MaxValue, false, "Failed with uint.MaxValue, negative")] public void CheckDate(uint year, uint month, uint day, bool cmp, string because) { - var result = DateUtil.IsDateValid(year, month, day); + var result = DateUtil.IsValidDate(year, month, day); result.Should().Be(cmp, because); }