The algorithms don't support a year 0. Years before Common Era (B.C.E. or B.C.) are negative and years of Common Era (C.E. or A.D.) are positive.
This class is not compatible to T:System.Globalization.JulianCalendar.
/// <summary> /// Overridden. Gives the number of days in the specified month /// of the given year and era. /// </summary> /// <param name="year">An integer that gives the year. /// </param> /// <param name="month">An integer that gives the month, starting /// with 1.</param> /// <param name="era">An intger that gives the era of the specified /// year.</param> /// <returns>An integer that gives the number of days of the /// specified month.</returns> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The exception is thrown, if <paramref name="month"/>, /// <paramref name="year"/> ,or <paramref name="era"/> is outside /// the allowed range. /// </exception> public override int GetDaysInMonth(int year, int month, int era) { M_CheckYME(year, month, ref era); int rd1 = CCJulianCalendar.fixed_from_dmy(1, month, year); int rd2 = CCJulianCalendar.fixed_from_dmy(1, month + 1, year); return(rd2 - rd1); }
public static int month_from_fixed(int date) { int result; int num; CCJulianCalendar.my_from_fixed(out result, out num, date); return(result); }
/// <summary> /// Overridden. Gives the number of the day in the year. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> that specifies a /// date. /// </param> /// <returns>An integer representing the day of the year, /// starting with 1.</returns> public override int GetDayOfYear(DateTime time) { int rd = CCFixed.FromDateTime(time); int year = CCJulianCalendar.year_from_fixed(rd); int rd1_1 = CCJulianCalendar.fixed_from_dmy(1, 1, year); return(rd - rd1_1 + 1); }
/// <summary>Returns the number of days in the specified year in the specified era.</summary> /// <returns>The number of days in the specified year in the specified era.</returns> /// <param name="year">An integer that represents the year. </param> /// <param name="era">An integer that represents the era. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="era" /> is outside the range supported by the calendar. -or- <paramref name="year" /> is outside the range supported by the calendar. </exception> public override int GetDaysInYear(int year, int era) { this.M_CheckYE(year, ref era); int num = CCJulianCalendar.fixed_from_dmy(1, 1, year); int num2 = CCJulianCalendar.fixed_from_dmy(1, 1, year + 1); return(num2 - num); }
/// <summary>Returns a <see cref="T:System.DateTime" /> that is set to the specified date and time in the specified era.</summary> /// <returns>The <see cref="T:System.DateTime" /> that is set to the specified date and time in the current era.</returns> /// <param name="year">An integer that represents the year. </param> /// <param name="month">An integer from 1 to 12 that represents the month. </param> /// <param name="day">An integer from 1 to 31 that represents the day. </param> /// <param name="hour">An integer from 0 to 23 that represents the hour. </param> /// <param name="minute">An integer from 0 to 59 that represents the minute. </param> /// <param name="second">An integer from 0 to 59 that represents the second. </param> /// <param name="millisecond">An integer from 0 to 999 that represents the millisecond. </param> /// <param name="era">An integer that represents the era. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="year" /> is outside the range supported by the calendar.-or- <paramref name="month" /> is outside the range supported by the calendar.-or- <paramref name="day" /> is outside the range supported by the calendar.-or- <paramref name="hour" /> is less than zero or greater than 23.-or- <paramref name="minute" /> is less than zero or greater than 59.-or- <paramref name="second" /> is less than zero or greater than 59.-or- <paramref name="millisecond" /> is less than zero or greater than 999. -or- <paramref name="era" /> is outside the range supported by the calendar. </exception> public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) { this.M_CheckYMDE(year, month, day, ref era); base.M_CheckHMSM(hour, minute, second, millisecond); int date = CCJulianCalendar.fixed_from_dmy(day, month, year); return(CCFixed.ToDateTime(date, hour, minute, second, (double)millisecond)); }
/// <summary>Returns the number of days in the specified month in the specified year in the specified era.</summary> /// <returns>The number of days in the specified month in the specified year in the specified era.</returns> /// <param name="year">An integer that represents the year. </param> /// <param name="month">An integer from 1 to 12 that represents the month. </param> /// <param name="era">An integer that represents the era. </param> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// <paramref name="era" /> is outside the range supported by the calendar. -or- <paramref name="year" /> is outside the range supported by the calendar.-or- <paramref name="month" /> is outside the range supported by the calendar. </exception> public override int GetDaysInMonth(int year, int month, int era) { this.M_CheckYME(year, month, ref era); int num = CCJulianCalendar.fixed_from_dmy(1, month, year); int num2 = CCJulianCalendar.fixed_from_dmy(1, month + 1, year); return(num2 - num); }
/// <summary>Returns the day of the year in the specified <see cref="T:System.DateTime" />.</summary> /// <returns>An integer from 1 to 366 that represents the day of the year in <paramref name="time" />.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to read. </param> public override int GetDayOfYear(DateTime time) { int num = CCFixed.FromDateTime(time); int year = CCJulianCalendar.year_from_fixed(num); int num2 = CCJulianCalendar.fixed_from_dmy(1, 1, year); return(num - num2 + 1); }
/// <summary> /// Overridden. Gives the number of days of the specified /// year of the given era. /// </summary> /// <param name="year">An integer that specifies the year. /// </param> /// <param name="era">An ineger that specifies the era. /// </param> /// <returns>An integer that gives the number of days of the /// specified year.</returns> /// <exception cref="T:System.ArgumentOutOfRangeExceiption"> /// The exception is thrown, if /// <paramref name="year"/> is outside the allowed range. /// </exception> public override int GetDaysInYear(int year, int era) { M_CheckYE(year, ref era); int rd1 = CCJulianCalendar.fixed_from_dmy(1, 1, year); int rd2 = CCJulianCalendar.fixed_from_dmy(1, 1, year + 1); return(rd2 - rd1); }
public static int day_from_fixed(int date) { int result; int num; int num2; CCJulianCalendar.dmy_from_fixed(out result, out num, out num2, date); return(result); }
/// <summary> /// Overridden. Creates the /// <see cref="T:System.DateTime"/> from the parameters. /// </summary> /// <param name="year">An integer that gives the year in the /// <paramref name="era"/>. /// </param> /// <param name="month">An integer that specifies the month. /// </param> /// <param name="day">An integer that specifies the day. /// </param> /// <param name="hour">An integer that specifies the hour. /// </param> /// <param name="minute">An integer that specifies the minute. /// </param> /// <param name="second">An integer that gives the second. /// </param> /// <param name="milliseconds">An integer that gives the /// milliseconds. /// </param> /// <param name="era">An integer that specifies the era. /// </param> /// <returns> /// <see cref="T:system.DateTime"/> representig the date and time. /// </returns> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The exception is thrown, if at least one of the parameters /// is out of range. /// </exception> public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int milliseconds, int era) { M_CheckYMDE(year, month, day, ref era); M_CheckHMSM(hour, minute, second, milliseconds); int rd = CCJulianCalendar.fixed_from_dmy(day, month, year); return(CCFixed.ToDateTime(rd, hour, minute, second, milliseconds)); }
/// <summary>Returns a <see cref="T:System.DateTime" /> that is the specified number of years 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 years to the specified <see cref="T:System.DateTime" />.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to which to add years. </param> /// <param name="years">The number of years to add. </param> /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception> public override DateTime AddYears(DateTime time, int years) { int date = CCFixed.FromDateTime(time); int day; int month; int num; CCJulianCalendar.dmy_from_fixed(out day, out month, out num, date); num += years; date = CCJulianCalendar.fixed_from_dmy(day, month, num); return(CCFixed.ToDateTime(date).Add(time.TimeOfDay)); }
/// <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 years to a given date. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> to which to add /// years. /// </param> /// <param name="years">The number of years to add.</param> /// <returns>A new <see cref="T:System.DateTime"/> value, that /// results from adding <paramref name="years"/> to the specified /// DateTime.</returns> public override DateTime AddYears(DateTime time, int years) { int rd = CCFixed.FromDateTime(time); int day, month, year; CCJulianCalendar.dmy_from_fixed( out day, out month, out year, rd); year += years; 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> /// 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 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 date_difference(int dayA, int monthA, int yearA, int dayB, int monthB, int yearB) { return(CCJulianCalendar.fixed_from_dmy(dayB, monthB, yearB) - CCJulianCalendar.fixed_from_dmy(dayA, monthA, yearA)); }
/// <summary> /// Overridden. Tells whether the given year /// is a leap year. /// </summary> /// <param name="year">An integer that specifies the year in the /// given era. /// </param> /// <param name="era">An integer that specifies the era. /// </param> /// <returns>A boolean that tells whether the given year is a leap /// year. /// </returns> /// <exception cref="T:System.ArgumentOutOfRangeException"> /// The exception is thrown, if the year or era is not /// valid. /// </exception> public override bool IsLeapYear(int year, int era) { M_CheckYE(year, ref era); return(CCJulianCalendar.is_leap_year(year)); }
/// <summary> /// Overridden. Gives the number of the year of the specified /// date. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> that specifies a /// date. /// </param> /// <returns>An integer representing the year, /// starting with 1.</returns> public override int GetYear(DateTime time) { int rd = CCFixed.FromDateTime(time); return(CCJulianCalendar.year_from_fixed(rd)); }
/// <summary> /// Overridden. Gives the number of the month of the specified /// date. /// </summary> /// <param name="time">The /// <see cref="T:System.DateTime"/> that specifies a /// date. /// </param> /// <returns>An integer representing the month, /// starting with 1.</returns> public override int GetMonth(DateTime time) { int rd = CCFixed.FromDateTime(time); return(CCJulianCalendar.month_from_fixed(rd)); }
/// <summary>Returns the day of the month in the specified <see cref="T:System.DateTime" />.</summary> /// <returns>An integer from 1 to 31 that represents the day of the month in <paramref name="time" />.</returns> /// <param name="time">The <see cref="T:System.DateTime" /> to read. </param> public override int GetDayOfMonth(DateTime time) { int date = CCFixed.FromDateTime(time); return(CCJulianCalendar.day_from_fixed(date)); }
public static int days_remaining(int day, int month, int year) { return(CCJulianCalendar.date_difference(day, month, year, 31, 12, year)); }
public static int day_number(int day, int month, int year) { return(CCJulianCalendar.date_difference(31, 12, year - 1, day, month, year)); }
public static void dmy_from_fixed(out int day, out int month, out int year, int date) { CCJulianCalendar.my_from_fixed(out month, out year, date); day = date - CCJulianCalendar.fixed_from_dmy(1, month, year) + 1; }