diff options
author | Kevin Daughtridge <kevin@kdau.com> | 2020-04-13 15:42:00 -0700 |
---|---|---|
committer | Kevin Daughtridge <kevin@kdau.com> | 2020-04-13 15:42:00 -0700 |
commit | 49c2ee517d3276b4547bb25ceda3ebf5e9707887 (patch) | |
tree | 493e937f7ddb13d8c4e871663c36dac984157800 /src/SMAPI/Utilities | |
parent | 5f73d47fb9dfe7ac2733a0a5fe57cf96639594f9 (diff) | |
download | SMAPI-49c2ee517d3276b4547bb25ceda3ebf5e9707887.tar.gz SMAPI-49c2ee517d3276b4547bb25ceda3ebf5e9707887.tar.bz2 SMAPI-49c2ee517d3276b4547bb25ceda3ebf5e9707887.zip |
SDate: Add WorldDate conversions and features
- SeasonIndex
- FromWorldDate()
- FromDaysSinceStart()
- ToLocaleString()
- ToWorldDate()
Diffstat (limited to 'src/SMAPI/Utilities')
-rw-r--r-- | src/SMAPI/Utilities/SDate.cs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs index 0ab37aa0..301ea9d2 100644 --- a/src/SMAPI/Utilities/SDate.cs +++ b/src/SMAPI/Utilities/SDate.cs @@ -29,6 +29,9 @@ namespace StardewModdingAPI.Utilities /// <summary>The season name.</summary> public string Season { get; } + /// <summary>The season index.</summary> + public int SeasonIndex { get; } + /// <summary>The year.</summary> public int Year { get; } @@ -63,6 +66,20 @@ namespace StardewModdingAPI.Utilities return new SDate(Game1.dayOfMonth, Game1.currentSeason, Game1.year, allowDayZero: true); } + /// <summary>Get the date equivalent to the given WorldDate.</summary> + /// <param name="worldDate">A date returned from a core game property or method.</param> + public static SDate FromWorldDate(WorldDate worldDate) + { + return new SDate(worldDate.DayOfMonth, worldDate.Season, worldDate.Year, allowDayZero: true); + } + + /// <summary>Get the date falling the given number of days after 0 spring Y1.</summary> + /// <param name="daysSinceStart">The number of days since 0 spring Y1.</param> + public static SDate FromDaysSinceStart(int daysSinceStart) + { + return new SDate(0, "spring", 1, allowDayZero: true).AddDays(daysSinceStart); + } + /// <summary>Get a new date with the given number of days added.</summary> /// <param name="offset">The number of days to add.</param> /// <returns>Returns the resulting date.</returns> @@ -98,6 +115,18 @@ namespace StardewModdingAPI.Utilities return $"{this.Day:00} {this.Season} Y{this.Year}"; } + /// <summary>Get a string representation of the date in the current game locale.</summary> + public string ToLocaleString() + { + return this.ToWorldDate().Localize(); + } + + /// <summary>Get the date as an instance of the game's WorldDate class. This is intended for passing to core game methods.</summary> + public WorldDate ToWorldDate() + { + return new WorldDate(this.Year, this.Season, this.Day); + } + /**** ** IEquatable ****/ @@ -200,6 +229,7 @@ namespace StardewModdingAPI.Utilities // initialize this.Day = day; this.Season = season; + this.SeasonIndex = this.GetSeasonIndex(season); this.Year = year; this.DayOfWeek = this.GetDayOfWeek(day); this.DaysSinceStart = this.GetDaysSinceStart(day, season, year); |