mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-24 04:53:08 +00:00
Merge pull request #175 from kwsch/b/year-2000-error
Fixed crash in DateUtil when Year is 0
This commit is contained in:
commit
c62df9f1a5
6 changed files with 19 additions and 6 deletions
|
@ -102,7 +102,7 @@ namespace PKHeX
|
|||
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 @@ namespace PKHeX
|
|||
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 @@ namespace PKHeX
|
|||
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 @@ namespace PKHeX
|
|||
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 @@ namespace PKHeX
|
|||
/// <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 @@ namespace PKHeX.Tests.PKM
|
|||
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 @@ namespace PKHeX.Tests.Util
|
|||
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()
|
||||
|
|
Loading…
Reference in a new issue