We are breaking the .Net naming conventions to be compatible to the "Calendrical Calculations" bool.
public static int div_mod(out int remainder, int x, int y) { int num = CCMath.div(x, y); remainder = x - y * num; return(num); }
public static int fixed_from_dmy(int day, int month, int year) { int num = 227013; num += 354 * (year - 1); num += CCMath.div(3 + 11 * year, 30); num += (int)Math.Ceiling(29.5 * (double)(month - 1)); return(num + day); }
public static bool is_leap_year(int year) { if (CCMath.mod(year, 4) != 0) { return(false); } int num = CCMath.mod(year, 400); return(num != 100 && num != 200 && num != 300); }
public static int year_from_fixed(int date) { int x = date - 1; int num = CCMath.div_mod(out x, x, 146097); int num2 = CCMath.div_mod(out x, x, 36524); int num3 = CCMath.div_mod(out x, x, 1461); int num4 = CCMath.div(x, 365); int num5 = 400 * num + 100 * num2 + 4 * num3 + num4; return((num2 != 4 && num4 != 4) ? (num5 + 1) : num5); }
/// <summary>Returns a <see cref="T:System.DateTime" /> that is the specified number of months away from the specified <see cref="T:System.DateTime" />.</summary> /// <returns>The <see cref="T:System.DateTime" /> that results from adding the specified number of months to the specified <see cref="T:System.DateTime" />.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param> /// <param name="months">The number of months to add. </param> /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="months" /> is less than -120000.-or- <paramref name="months" /> is greater than 120000. </exception> public override DateTime AddMonths(DateTime time, int months) { int date = CCFixed.FromDateTime(time); int day; int num; int num2; CCJulianCalendar.dmy_from_fixed(out day, out num, out num2, date); num += months; num2 += CCMath.div_mod(out num, num, 12); date = CCJulianCalendar.fixed_from_dmy(day, num, num2); return(CCFixed.ToDateTime(date).Add(time.TimeOfDay)); }
/// <summary> /// Overridden. Adds months to a given date. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> to which to add /// months. /// </param> /// <param name="months">The number of months to add.</param> /// <returns>A new <see cref="T:System.DateTime"/> value, that /// results from adding <paramref name="months"/> to the specified /// DateTime.</returns> public override DateTime AddMonths(DateTime time, int months) { int rd = CCFixed.FromDateTime(time); int day, month, year; CCJulianCalendar.dmy_from_fixed( out day, out month, out year, rd); month += months; year += CCMath.div_mod(out month, month, 12); rd = CCJulianCalendar.fixed_from_dmy(day, month, year); DateTime t = CCFixed.ToDateTime(rd); return(t.Add(time.TimeOfDay)); }
public static int fixed_from_dmy(int day, int month, int year) { int num = (year >= 0) ? year : (year + 1); int num2 = -2; num2 += 365 * (num - 1); num2 += CCMath.div(num - 1, 4); num2 += CCMath.div(367 * month - 362, 12); if (month > 2) { num2 += ((!CCJulianCalendar.is_leap_year(year)) ? -2 : -1); } return(num2 + day); }
/// <summary>Calculates a date that is a specified number of months away from a specified initial date.</summary> /// <returns>A <see cref="T:System.DateTime" /> that represents the date yielded by adding the number of months specified by the <paramref name="months" /> parameter to the date specified by the <paramref name="time" /> parameter.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. The <see cref="T:System.Globalization.UmAlQuraCalendar" /> class supports only dates from 04/30/1900 00.00.00 (Gregorian date) through 05/13/2029 23:59:59 (Gregorian date).</param> /// <param name="months">The positive or negative number of months to add. </param> /// <exception cref="T:System.ArgumentException">The resulting date is outside the range supported by the <see cref="T:System.Globalization.UmAlQuraCalendar" /> class. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="months" /> is less than -120,000 or greater than 120,000. -or-<paramref name="time" /> is outside the range supported by this calendar.</exception> public override DateTime AddMonths(DateTime time, int months) { int num = this.M_FromDateTime(time); int day; int num2; int num3; CCHijriCalendar.dmy_from_fixed(out day, out num2, out num3, num); num2 += months; num3 += CCMath.div_mod(out num2, num2, 12); num = CCHijriCalendar.fixed_from_dmy(day, num2, num3); this.M_CheckFixedHijri("time", num); return(this.M_ToDateTime(num).Add(time.TimeOfDay)); }
public static int elapsed_days(int year) { int num = CCMath.div(235 * year - 234, 19); int num3; int num2 = CCMath.div_mod(out num3, num, 1080); int x = 204 + 793 * num3; int x2 = 11 + 12 * num + 793 * num2 + CCMath.div(x, 1080); int num4 = 29 * num + CCMath.div(x2, 24); if (CCMath.mod(3 * (num4 + 1), 7) < 3) { num4++; } return(num4); }
public static int fixed_from_dmy(int day, int month, int year) { int num = 0; num += 365 * (year - 1); num += CCMath.div(year - 1, 4); num -= CCMath.div(year - 1, 100); num += CCMath.div(year - 1, 400); num += CCMath.div(367 * month - 362, 12); if (month > 2) { num += ((!CCGregorianCalendar.is_leap_year(year)) ? -2 : -1); } return(num + day); }
/// <summary> /// Overrideden. Adds months to a given date. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> to which to add /// months. /// </param> /// <param name="months">The number of months to add.</param> /// <returns>A new <see cref="T:System.DateTime"/> value, that /// results from adding <paramref name="months"/> to the specified /// DateTime.</returns> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The exception is thrown if the /// <see cref="T:System.DateTime"/> return value is not in the /// supported range of the Hijri calendar. /// </exception> public override DateTime AddMonths(DateTime time, int months) { int rd = M_FromDateTime(time); int day, month, year; CCHijriCalendar.dmy_from_fixed( out day, out month, out year, rd); month += months; year += CCMath.div_mod(out month, month, 12); rd = CCHijriCalendar.fixed_from_dmy(day, month, year); M_CheckFixedHijri("time", rd); DateTime t = M_ToDateTime(rd); return(t.Add(time.TimeOfDay)); }
/// <summary>Returns a <see cref="T:System.DateTime" /> that is offset the specified number of months from the specified <see cref="T:System.DateTime" />.</summary> /// <returns>A <see cref="T:System.DateTime" /> that represents the date yielded by adding the number of months specified by the <paramref name="months" /> parameter to the date specified by the <paramref name="time" /> parameter.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param> /// <param name="months">The positive or negative number of months to add. </param> /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="months" /> is less than -120,000 or greater than 120,000. </exception> public override DateTime AddMonths(DateTime time, int months) { int date = CCFixed.FromDateTime(time); int day; int num; int num2; this.dmy_from_fixed(out day, out num, out num2, date); num += months; num2 += CCMath.div_mod(out num, num, 12); date = this.fixed_from_dmy(day, num, num2); DateTime dateTime = CCFixed.ToDateTime(date).Add(time.TimeOfDay); this.M_CheckDateTime(dateTime); return(dateTime); }
public static DateTime AddMonths(DateTime time, int months) { int date = CCFixed.FromDateTime(time); int num; int num2; int num3; CCGregorianCalendar.dmy_from_fixed(out num, out num2, out num3, date); num2 += months; num3 += CCMath.div_mod(out num2, num2, 12); int daysInMonth = CCGregorianCalendar.GetDaysInMonth(num3, num2); if (num > daysInMonth) { num = daysInMonth; } date = CCGregorianCalendar.fixed_from_dmy(num, num2, num3); return(CCFixed.ToDateTime(date).Add(time.TimeOfDay)); }
public static void my_from_fixed(out int month, out int year, int date) { year = CCJulianCalendar.year_from_fixed(date); int num = date - CCJulianCalendar.fixed_from_dmy(1, 1, year); int num2; if (date < CCJulianCalendar.fixed_from_dmy(1, 3, year)) { num2 = 0; } else if (CCJulianCalendar.is_leap_year(year)) { num2 = 1; } else { num2 = 2; } month = CCMath.div(12 * (num + num2) + 373, 367); }
public static int year_from_fixed(int date) { int num = CCMath.div(4 * (date - -1) + 1464, 1461); return((num > 0) ? num : (num - 1)); }
public static DayOfWeek day_of_week(int date) { return((DayOfWeek)CCMath.mod(date, 7)); }
public static int amod(int x, int y) { int num = CCMath.mod(x, y); return((num != 0) ? num : y); }
public static double amod(double x, double y) { double num = CCMath.mod(x, y); return((num != 0.0) ? num : y); }
public static bool short_kislev(int year) { return(CCMath.mod(CCHebrewCalendar.days_in_year(year), 10) == 3); }
public static int mod(int x, int y) { return(x - y * CCMath.div(x, y)); }
public static bool is_leap_year(int year) { return(CCMath.mod(14 + 11 * year, 30) < 11); }
public static int year_from_fixed(int date) { return(CCMath.div(30 * (date - 227014) + 10646, 10631)); }
public static bool is_leap_year(int year) { return(CCMath.mod(7 * year + 1, 19) < 7); }
public static bool is_leap_year(int year) { return(CCMath.mod(year, 4) == ((year <= 0) ? 3 : 0)); }
public static bool long_heshvan(int year) { return(CCMath.mod(CCHebrewCalendar.days_in_year(year), 10) == 5); }