Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ AddMonths()

DateTime System.Globalization.GregorianCalendarHelper.AddMonths ( DateTime time,
int months )
inline

Definition at line 196 of file GregorianCalendarHelper.cs.

197 {
198 if (months < -120000 || months > 120000)
199 {
200 throw new ArgumentOutOfRangeException("months", SR.Format(SR.ArgumentOutOfRange_Range, -120000, 120000));
201 }
202 CheckTicksRange(time.Ticks);
203 int datePart = GetDatePart(time.Ticks, 0);
204 int datePart2 = GetDatePart(time.Ticks, 2);
205 int num = GetDatePart(time.Ticks, 3);
206 int num2 = datePart2 - 1 + months;
207 if (num2 >= 0)
208 {
209 datePart2 = num2 % 12 + 1;
210 datePart += num2 / 12;
211 }
212 else
213 {
214 datePart2 = 12 + (num2 + 1) % 12;
215 datePart += (num2 - 11) / 12;
216 }
217 int[] array = ((datePart % 4 == 0 && (datePart % 100 != 0 || datePart % 400 == 0)) ? DaysToMonth366 : DaysToMonth365);
218 int num3 = array[datePart2] - array[datePart2 - 1];
219 if (num > num3)
220 {
221 num = num3;
222 }
223 long ticks = DateToTicks(datePart, datePart2, num) + time.Ticks % 864000000000L;
224 Calendar.CheckAddResult(ticks, m_Cal.MinSupportedDateTime, m_Cal.MaxSupportedDateTime);
225 return new DateTime(ticks);
226 }
virtual DateTime MaxSupportedDateTime
Definition Calendar.cs:15
virtual DateTime MinSupportedDateTime
Definition Calendar.cs:13
static long DateToTicks(int year, int month, int day)

References System.SR.ArgumentOutOfRange_Range, System.array, System.Globalization.Calendar.CheckAddResult(), System.Globalization.GregorianCalendarHelper.CheckTicksRange(), System.DateTime, System.Globalization.GregorianCalendarHelper.DateToTicks(), System.Globalization.GregorianCalendarHelper.DaysToMonth365, System.Globalization.GregorianCalendarHelper.DaysToMonth366, System.SR.Format(), System.Globalization.GregorianCalendarHelper.GetDatePart(), System.L, System.Globalization.GregorianCalendarHelper.m_Cal, System.Globalization.Calendar.MaxSupportedDateTime, System.Globalization.Calendar.MinSupportedDateTime, and System.DateTime.Ticks.

Referenced by System.Globalization.JapaneseCalendar.AddMonths(), System.Globalization.KoreanCalendar.AddMonths(), System.Globalization.TaiwanCalendar.AddMonths(), System.Globalization.ThaiBuddhistCalendar.AddMonths(), and System.Globalization.GregorianCalendarHelper.AddYears().