From 230ab1738af34c89e9c308d2ce4976d4ae8dbe70 Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Fri, 16 Jun 2017 03:47:36 -0700 Subject: - This adds in operators to SDate. And Tests. And a NUnit Adapter - sorry about the latter.. --- src/StardewModdingAPI/Utilities/SDate.cs | 150 +++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) (limited to 'src/StardewModdingAPI') 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 + *********/ + + /// + /// Equality operator. Tests the date being equal to each other + /// + /// The first date being compared + /// The second date being compared + /// The equality of the dates + 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; + } + + /// + /// Inequality operator. Tests the date being not equal to each other + /// + /// The first date being compared + /// The second date being compared + /// The inequality of the dates + 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; + } + + /// + /// Less than operator. Tests the date being less than to each other + /// + /// The first date being compared + /// The second date being compared + /// If the dates are less than + 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; + } + + /// + /// Less or equal than operator. Tests the date being less than or equal to each other + /// + /// The first date being compared + /// The second date being compared + /// If the dates are less than or equal than + 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; + } + + /// + /// Greater or equal than operator. Tests the date being greater than or equal to each other + /// + /// The first date being compared + /// The second date being compared + /// If the dates are greater than or equal than + 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; + } + + /// + /// Greater than operator. Tests the date being greater than to each other + /// + /// The first date being compared + /// The second date being compared + /// If the dates are greater than + 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; + } + + /// + /// Overrides the equals function. + /// + /// Object being compared. + /// The equalaity of the object. + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + /// + /// This returns the hashcode of the object + /// + /// The hashcode of the object. + public override int GetHashCode() + { + return base.GetHashCode(); + } /********* ** Private methods -- cgit