mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-02 23:28:21 -05:00
Fixed crash in DateUtil when Year is 0
This commit is contained in:
@@ -102,7 +102,7 @@ public override string CardTitle
|
||||
get
|
||||
{
|
||||
// Check to see if date is valid
|
||||
if (!Util.IsDateValid(Year, Month, Day))
|
||||
if (!Util.IsDateValid(2000 + Year, Month, Day))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public WC6(byte[] data = null)
|
||||
get
|
||||
{
|
||||
// Check to see if date is valid
|
||||
if (!Util.IsDateValid(Year, Month, Day))
|
||||
if (!Util.IsDateValid(2000 + Year, Month, Day))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public byte[] Write()
|
||||
get
|
||||
{
|
||||
// Check to see if date is valid
|
||||
if (!Util.IsDateValid(Met_Year, Met_Month, Met_Day))
|
||||
if (!Util.IsDateValid(2000 + Met_Year, Met_Month, Met_Day))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public byte[] Write()
|
||||
get
|
||||
{
|
||||
// Check to see if date is valid
|
||||
if (!Util.IsDateValid(Egg_Year, Egg_Month, Egg_Day))
|
||||
if (!Util.IsDateValid(2000 + Egg_Year, Egg_Month, Egg_Day))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public static partial class Util
|
||||
/// <returns>A boolean indicating whether or not the date is valid.</returns>
|
||||
public static bool IsDateValid(int year, int month, int day)
|
||||
{
|
||||
return !(year < 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth(year, month));
|
||||
return !(year <= 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth(year, month));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,13 +22,19 @@ public void MetDateGetterTest()
|
||||
pk.MetDay = 0;
|
||||
pk.MetMonth = 0;
|
||||
pk.MetYear = 0;
|
||||
Assert.IsFalse(pk.MetDate.HasValue, "MetDate should be null when date components are all 0.");
|
||||
Assert.IsFalse(pk.MetDate.HasValue, "MetDate should be null when date components are all 0.");
|
||||
|
||||
// Ensure MetDate gives correct date
|
||||
pk.MetDay = 10;
|
||||
pk.MetMonth = 8;
|
||||
pk.MetYear = 16;
|
||||
Assert.AreEqual(new DateTime(2016, 8, 10).Date, pk.MetDate.Value.Date, "Met date does not return correct date.");
|
||||
|
||||
// Ensure 0 year is calculated correctly
|
||||
pk.MetDay = 1;
|
||||
pk.MetMonth = 1;
|
||||
pk.MetYear = 0;
|
||||
Assert.AreEqual(2000, pk.MetDate.Value.Date.Year, "Year is not calculated correctly.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -101,6 +101,13 @@ public void FailsWithZeroMonth()
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2000, 0, 1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithZeroYear()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(0, 1, 1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void TestUIntOverload()
|
||||
|
||||
Reference in New Issue
Block a user