add weekday property to SDate (#339)

This commit is contained in:
Nicholas Johnson 2017-08-01 12:27:02 -07:00 committed by Jesse Plamondon-Willard
parent 3599daee45
commit 4ff15b9da9
1 changed files with 31 additions and 1 deletions

View File

@ -19,6 +19,8 @@ namespace StardewModdingAPI.Utilities
/// <summary>The number of days in a season.</summary>
private readonly int DaysInSeason = 28;
/// <summary>The Day of the Week this date has</summary>
public DayOfWeek Weekday;
/*********
** Accessors
@ -32,7 +34,6 @@ namespace StardewModdingAPI.Utilities
/// <summary>The year.</summary>
public int Year { get; }
/*********
** Public methods
*********/
@ -64,6 +65,8 @@ namespace StardewModdingAPI.Utilities
this.Day = day;
this.Season = season;
this.Year = year;
this.Weekday = GetDayOfWeek();
}
/// <summary>Get the current in-game date.</summary>
@ -114,6 +117,33 @@ namespace StardewModdingAPI.Utilities
return $"{this.Day:00} {this.Season} Y{this.Year}";
}
/// <summary>
/// This gets the day of the week from the date
/// </summary>
/// <returns>A constant describing the day</returns>
private DayOfWeek GetDayOfWeek()
{
switch (this.Day % 7)
{
case 0:
return DayOfWeek.Sunday;
case 1:
return DayOfWeek.Monday;
case 2:
return DayOfWeek.Tuesday;
case 3:
return DayOfWeek.Wednesday;
case 4:
return DayOfWeek.Thursday;
case 5:
return DayOfWeek.Friday;
case 6:
return DayOfWeek.Saturday;
default:
return 0;
}
}
/****
** IEquatable
****/