diff options
author | Nicholas Johnson <koihimenakamura@gmail.com> | 2017-06-16 03:47:36 -0700 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2017-06-18 23:21:37 +0100 |
commit | 230ab1738af34c89e9c308d2ce4976d4ae8dbe70 (patch) | |
tree | 34f62eeb8f730aaab4702a45c35a8443dd176deb /src/StardewModdingAPI | |
parent | 3c3953a7fdca6e79f50a4a5474be69ca6aab6446 (diff) | |
download | SMAPI-230ab1738af34c89e9c308d2ce4976d4ae8dbe70.tar.gz SMAPI-230ab1738af34c89e9c308d2ce4976d4ae8dbe70.tar.bz2 SMAPI-230ab1738af34c89e9c308d2ce4976d4ae8dbe70.zip |
- This adds in operators to SDate. And Tests. And a NUnit Adapter - sorry about the latter..
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Utilities/SDate.cs | 150 |
1 files changed, 150 insertions, 0 deletions
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 |