fix year edge case in date calculations

This commit is contained in:
Jesse Plamondon-Willard 2019-06-09 16:26:01 -04:00
parent c28c3ff081
commit b47329d5b8
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 4 additions and 3 deletions

View File

@ -53,6 +53,7 @@ Released 13 September 2019 for Stardew Valley 1.3.36.
* Fixed 'location list changed' verbose log not correctly listing changes.
* Fixed mods able to directly load (and in some cases edit) a different mod's local assets using internal asset key forwarding.
* Fixed changes to a map loaded by a mod being persisted across content managers.
* Fixed `SDate.AddDays` incorrectly changing year when the result is exactly winter 28.
## 2.11.2
Released 23 April 2019 for Stardew Valley 1.3.36.

View File

@ -159,7 +159,7 @@ namespace StardewModdingAPI.Tests.Utilities
[TestCase("15 summer Y1", -28, ExpectedResult = "15 spring Y1")] // negative season transition
[TestCase("15 summer Y2", -28 * 4, ExpectedResult = "15 summer Y1")] // negative year transition
[TestCase("01 spring Y3", -(28 * 7 + 17), ExpectedResult = "12 spring Y1")] // negative year transition
[TestCase("06 fall Y2", 50, ExpectedResult = "28 winter Y3")] // test for zero-index errors
[TestCase("06 fall Y2", 50, ExpectedResult = "28 winter Y2")] // test for zero-index errors
[TestCase("06 fall Y2", 51, ExpectedResult = "01 spring Y3")] // test for zero-index errors
public string AddDays(string dateStr, int addDays)
{

View File

@ -86,7 +86,7 @@ namespace StardewModdingAPI.Utilities
seasonIndex %= 4;
// get year
int year = hashCode / (this.Seasons.Length * this.DaysInSeason) + 1;
int year = (int)Math.Ceiling(hashCode / (this.Seasons.Length * this.DaysInSeason * 1m));
// create date
return new SDate(day, this.Seasons[seasonIndex], year);
@ -192,7 +192,7 @@ namespace StardewModdingAPI.Utilities
throw new ArgumentException($"Unknown season '{season}', must be one of [{string.Join(", ", this.Seasons)}].");
if (day < 0 || day > this.DaysInSeason)
throw new ArgumentException($"Invalid day '{day}', must be a value from 1 to {this.DaysInSeason}.");
if(day == 0 && !(allowDayZero && this.IsDayZero(day, season, year)))
if (day == 0 && !(allowDayZero && this.IsDayZero(day, season, year)))
throw new ArgumentException($"Invalid day '{day}', must be a value from 1 to {this.DaysInSeason}.");
if (year < 1)
throw new ArgumentException($"Invalid year '{year}', must be at least 1.");