From 3a247fa75c56f315d82ea55143e89d28d61c064c Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 15 Apr 2020 19:20:53 -0400 Subject: tweak new code, update release notes --- src/SMAPI/Utilities/SDate.cs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 8cb55891..36907714 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -29,7 +29,8 @@ namespace StardewModdingAPI.Utilities /// The season name. public string Season { get; } - /// The season index. + /// The index of the season (where 0 is spring, 1 is summer, 2 is fall, and 3 is winter). + /// This is used in some game calculations (e.g. seasonal game sprites) and methods (e.g. ). public int SeasonIndex { get; } /// The year. @@ -66,7 +67,7 @@ namespace StardewModdingAPI.Utilities return new SDate(Game1.dayOfMonth, Game1.currentSeason, Game1.year, allowDayZero: true); } - /// Get the date falling the given number of days after 0 spring Y1. + /// Get a date from the number of days after 0 spring Y1. /// The number of days since 0 spring Y1. public static SDate FromDaysSinceStart(int daysSinceStart) { @@ -80,6 +81,16 @@ namespace StardewModdingAPI.Utilities } } + /// Get a date from a game date instance. + /// The world date. + public static SDate From(WorldDate date) + { + if (date == null) + return null; + + return new SDate(date.DayOfMonth, date.Season, date.Year, allowDayZero: true); + } + /// Get a new date with the given number of days added. /// The number of days to add. /// Returns the resulting date. @@ -109,13 +120,19 @@ namespace StardewModdingAPI.Utilities return new SDate(day, this.Seasons[seasonIndex], year); } + /// Get a game date representation of the date. + public WorldDate ToWorldDate() + { + return new WorldDate(this.Year, this.Season, this.Day); + } + /// Get a string representation of the date. This is mainly intended for debugging or console messages. public override string ToString() { return $"{this.Day:00} {this.Season} Y{this.Year}"; } - /// Get a string representation of the date in the current game locale. + /// Get a translated string representation of the date in the current game locale. public string ToLocaleString() { return Utility.getDateStringFor(this.Day, this.SeasonIndex, this.Year); @@ -147,19 +164,6 @@ namespace StardewModdingAPI.Utilities /**** ** Operators ****/ - /// Get the SDate equivalent to the given WorldDate. - /// A date returned from a core game property or method. - public static explicit operator SDate(WorldDate worldDate) - { - return new SDate(worldDate.DayOfMonth, worldDate.Season, worldDate.Year, allowDayZero: true); - } - - /// Get the SDate as an instance of the game's WorldDate class. This is intended for passing to core game methods. - public static explicit operator WorldDate(SDate date) - { - return new WorldDate(date.Year, date.Season, date.Day); - } - /// Get whether one date is equal to another. /// The base date to compare. /// The other date to compare. -- cgit