I am using the DateTime.AddDays function on my Unity project, built for iOS. Everything compiles fine and I can run my project through xCode. The dates that I use for my function are correct. However, when I use the “AddDays” function, I suddenly get an “Argumentoutof range” error…
I don’t understand what I’m doing wrong.
public DateTime GetWeekStart(DateTime currTime, DayOfWeek startOfWeek)
{
double diff = (double)(currTime.DayOfWeek - startOfWeek);
if (diff < 0) {
diff += 7;
}
double addAmount = -1 * diff;
return currTime.AddDays(addAmount);
}
Here is the error that I’m getting:
ArgumentOutOfRangeException: Argument is out of range.
at System.DateTime.AddTicks (Int64 value) [0x00000] in <filename unknown>:0
at System.DateTime.AddMilliseconds (Double value) [0x00000] in <filename unknown>:0
at System.DateTime.AddDays (Double value) [0x00000] in <filename unknown>:0
at DataManager.GetWeekStart (DateTime currTime, DayOfWeek startOfWeek) [0x00000] in <filename unknown>:0