summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/StardewModdingAPI.Tests/SDateTests.cs41
-rw-r--r--src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj3
-rw-r--r--src/StardewModdingAPI.Tests/packages.config1
-rw-r--r--src/StardewModdingAPI/Utilities/SDate.cs150
4 files changed, 195 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Tests/SDateTests.cs b/src/StardewModdingAPI.Tests/SDateTests.cs
index a4c65a98..1cce6335 100644
--- a/src/StardewModdingAPI.Tests/SDateTests.cs
+++ b/src/StardewModdingAPI.Tests/SDateTests.cs
@@ -83,6 +83,47 @@ namespace StardewModdingAPI.Tests
return this.ParseDate(dateStr).AddDays(addDays).ToString();
}
+ [Test(Description = "Assert that the equality operators work as expected")]
+ public void EqualityOperators()
+ {
+ SDate s1 = new SDate(1, "spring", 2);
+ SDate s2 = new SDate(1, "spring", 2);
+ SDate s3 = new SDate(1, "spring", 3);
+ SDate s4 = new SDate(12, "spring", 2);
+ SDate s5 = new SDate(1, "summer", 2);
+
+ Assert.AreEqual(true, s1 == s2);
+ Assert.AreNotEqual(true, s1 == s3);
+ Assert.AreNotEqual(true, s1 == s4);
+ Assert.AreNotEqual(true, s1 == s5);
+ }
+
+ [Test(Description = "Assert that the comparison operators work as expected")]
+ public void ComparisonOperators()
+ {
+ SDate s1 = new SDate(1, "spring", 2);
+ SDate s2 = new SDate(1, "spring", 2);
+ SDate s3 = new SDate(1, "spring", 3);
+ SDate s4 = new SDate(12, "spring", 2);
+ SDate s5 = new SDate(1, "summer", 2);
+ SDate s6 = new SDate(1, "winter", 1);
+ SDate s7 = new SDate(13, "fall", 1);
+
+ Assert.AreEqual(true, s1 <= s2);
+ Assert.AreEqual(true, s1 >= s2);
+ Assert.AreEqual(true, s1 < s4);
+ Assert.AreEqual(true, s1 <= s4);
+ Assert.AreEqual(true, s4 > s1);
+ Assert.AreEqual(true, s4 >= s1);
+ Assert.AreEqual(true, s5 > s7);
+ Assert.AreEqual(true, s5 >= s7);
+ Assert.AreEqual(true, s6 < s5);
+ Assert.AreEqual(true, s6 <= s5);
+ Assert.AreEqual(true, s1 < s5);
+ Assert.AreEqual(true, s1 <= s5);
+ Assert.AreEqual(true, s5 > s1);
+ Assert.AreEqual(true, s5 >= s1);
+ }
/*********
** Private methods
diff --git a/src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj b/src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj
index 3ddb1326..fbce657d 100644
--- a/src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj
+++ b/src/StardewModdingAPI.Tests/StardewModdingAPI.Tests.csproj
@@ -63,6 +63,9 @@
<Name>StardewModdingAPI</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+ </ItemGroup>
<Import Project="$(SolutionDir)\crossplatform.targets" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> \ No newline at end of file
diff --git a/src/StardewModdingAPI.Tests/packages.config b/src/StardewModdingAPI.Tests/packages.config
index ba954308..d25dae06 100644
--- a/src/StardewModdingAPI.Tests/packages.config
+++ b/src/StardewModdingAPI.Tests/packages.config
@@ -4,4 +4,5 @@
<package id="Moq" version="4.7.10" targetFramework="net45" />
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="NUnit" version="3.6.1" targetFramework="net452" />
+ <package id="NUnit3TestAdapter" version="3.7.0" targetFramework="net45" />
</packages> \ No newline at end of file
diff --git a/src/StardewModdingAPI/Utilities/SDate.cs b/src/StardewModdingAPI/Utilities/SDate.cs
index 4729bfb9..fdeffe80 100644
--- a/src/StardewModdingAPI/Utilities/SDate.cs
+++ b/src/StardewModdingAPI/Utilities/SDate.cs
@@ -113,6 +113,156 @@ namespace StardewModdingAPI.Utilities
return new SDate(Game1.dayOfMonth, Game1.currentSeason, Game1.year);
}
+ /*********
+ ** Operator methods
+ *********/
+
+ /// <summary>
+ /// Equality operator. Tests the date being equal to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>The equality of the dates</returns>
+ public static bool operator ==(SDate s1, SDate s2)
+ {
+ if (s1.Day == s2.Day && s1.Year == s2.Year && s1.Season == s2.Season)
+ return true;
+ else
+ return false;
+ }
+
+ /// <summary>
+ /// Inequality operator. Tests the date being not equal to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>The inequality of the dates</returns>
+ public static bool operator !=(SDate s1, SDate s2)
+ {
+ if (s1.Day == s2.Day && s1.Year == s2.Year && s1.Season == s2.Season)
+ return false;
+ else
+ return true;
+ }
+
+ /// <summary>
+ /// Less than operator. Tests the date being less than to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>If the dates are less than</returns>
+ public static bool operator >(SDate s1, SDate s2)
+ {
+ if (s1.Year > s2.Year)
+ return true;
+ else if (s1.Year == s2.Year)
+ {
+ if (s1.Season == "winter" && s2.Season != "winter")
+ return true;
+ else if (s1.Season == s2.Season && s1.Day > s2.Day)
+ return true;
+ if (s1.Season == "fall" && (s2.Season == "summer" || s2.Season == "spring"))
+ return true;
+ if (s1.Season == "summer" && s2.Season == "spring")
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Less or equal than operator. Tests the date being less than or equal to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>If the dates are less than or equal than</returns>
+ public static bool operator >=(SDate s1, SDate s2)
+ {
+ if (s1.Year > s2.Year)
+ return true;
+ else if (s1.Year == s2.Year)
+ {
+ if (s1.Season == "winter" && s2.Season != "winter")
+ return true;
+ else if (s1.Season == s2.Season && s1.Day >= s2.Day)
+ return true;
+ if (s1.Season == "fall" && (s2.Season == "summer" || s2.Season == "spring"))
+ return true;
+ if (s1.Season == "summer" && s2.Season == "spring")
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Greater or equal than operator. Tests the date being greater than or equal to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>If the dates are greater than or equal than</returns>
+ public static bool operator <=(SDate s1, SDate s2)
+ {
+ if (s1.Year < s2.Year)
+ return true;
+ else if (s1.Year == s2.Year)
+ {
+ if (s1.Season == s2.Season && s1.Day <= s2.Day)
+ return true;
+ else if (s1.Season == "spring" && s2.Season != "spring")
+ return true;
+ if (s1.Season == "summer" && (s2.Season == "fall" || s2.Season == "winter"))
+ return true;
+ if (s1.Season == "fall" && s2.Season == "winter")
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Greater than operator. Tests the date being greater than to each other
+ /// </summary>
+ /// <param name="s1">The first date being compared</param>
+ /// <param name="s2">The second date being compared</param>
+ /// <returns>If the dates are greater than</returns>
+ public static bool operator <(SDate s1, SDate s2)
+ {
+ if (s1.Year < s2.Year)
+ return true;
+ else if (s1.Year == s2.Year)
+ {
+ if (s1.Season == s2.Season && s1.Day < s2.Day)
+ return true;
+ else if (s1.Season == "spring" && s2.Season != "spring")
+ return true;
+ if (s1.Season == "summer" && (s2.Season == "fall" || s2.Season == "winter"))
+ return true;
+ if (s1.Season == "fall" && s2.Season == "winter")
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Overrides the equals function.
+ /// </summary>
+ /// <param name="obj">Object being compared.</param>
+ /// <returns>The equalaity of the object.</returns>
+ public override bool Equals(object obj)
+ {
+ return base.Equals(obj);
+ }
+
+ /// <summary>
+ /// This returns the hashcode of the object
+ /// </summary>
+ /// <returns>The hashcode of the object.</returns>
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
/*********
** Private methods