A class encapsulating the functions of the Islamic calendar as static methods.

There is no difference here in using Hijri or Islamic calendar.

The epoch of the Islamic calendar isn't fixed, because we cannot surely say today, when the crescent of the new moon has been observed around the July 16, 622 C.E. Julian. Even today the start and end of the month Ramadan is defined by religous authorities. So the calendar can be offset by two days.

We don't support the offset here, however we changed the epoch from "Calendrical Calculations" to value, that .Net seems to be using.

This class is not compatible to T:System.Globalization.HijriCalendar.

T:CCFixed
示例#1
0
        /// <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>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// The exception is thrown if the
        /// <see cref="T:System.DateTime"/> parameter is not in the
        /// supported range of the Hijri calendar.
        /// </exception>
        public override int GetYear(DateTime time)
        {
            int rd = M_FromDateTime(time);

            M_CheckFixedHijri("time", rd);
            return(CCHijriCalendar.year_from_fixed(rd));
        }
示例#2
0
 internal void M_CheckFixedHijri(string param, int rdHijri)
 {
     if (rdHijri < UmAlQuraCalendar.M_MinFixed || rdHijri > UmAlQuraCalendar.M_MaxFixed - this.AddHijriDate)
     {
         StringWriter stringWriter = new StringWriter();
         int          num;
         int          num2;
         int          num3;
         CCHijriCalendar.dmy_from_fixed(out num, out num2, out num3, UmAlQuraCalendar.M_MaxFixed - this.AddHijriDate);
         if (this.AddHijriDate != 0)
         {
             stringWriter.Write("This HijriCalendar (AddHijriDate {0}) allows dates from 1. 1. 1 to {1}. {2}. {3}.", new object[]
             {
                 this.AddHijriDate,
                 num,
                 num2,
                 num3
             });
         }
         else
         {
             stringWriter.Write("HijriCalendar allows dates from 1.1.1 to {0}.{1}.{2}.", num, num2, num3);
         }
         throw new ArgumentOutOfRangeException(param, stringWriter.ToString());
     }
 }
示例#3
0
 /// <summary>
 /// A protected method checking an
 /// <see cref="F:AddHijriDate"/> adjusted fixed day number.
 /// </summary>
 /// <param name="param">A string giving the name of the parameter
 /// to check.</param>
 /// <param name="rdHijri">An integer giving the AddHijriDate adjusted
 /// fixed day number.
 /// </param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// Exception is thrown, if the AddHijriDate adjusted fixed day
 /// number is outside the supported range.
 /// </exception>
 internal void M_CheckFixedHijri(string param, int rdHijri)
 {
     if (rdHijri < M_MinFixed || rdHijri > M_MaxFixed - AddHijriDate)
     {
         StringWriter sw = new StringWriter();
         int          day, month, year;
         CCHijriCalendar.dmy_from_fixed(out day, out month,
                                        out year, M_MaxFixed - AddHijriDate);
         if (AddHijriDate != 0)
         {
             sw.Write("This HijriCalendar " +
                      "(AddHijriDate {0})" +
                      " allows dates from 1. 1. 1 to " +
                      "{1}. {2}. {3}.",
                      AddHijriDate,
                      day, month, year);
         }
         else
         {
             sw.Write("HijriCalendar allows dates from " +
                      "1.1.1 to {0}.{1}.{2}.",
                      day, month, year);
         }
         throw new ArgumentOutOfRangeException(param,
                                               sw.ToString());
     }
 }
示例#4
0
        /// <summary>Calculates the year of a date represented by a specified <see cref="T:System.DateTime" />.</summary>
        /// <returns>An integer that represents the year specified by the <paramref name="time" /> parameter.</returns>
        /// <param name="time">The <see cref="T:System.DateTime" /> to read. 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>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="time" /> is outside the range supported by this calendar. </exception>
        public override int GetYear(DateTime time)
        {
            int num = this.M_FromDateTime(time);

            this.M_CheckFixedHijri("time", num);
            return(CCHijriCalendar.year_from_fixed(num));
        }
示例#5
0
        /// <summary>
        /// Overriden. Gets the day of the month from
        /// <paramref name="time"/>.
        /// </summary>
        /// <param name="time">The
        /// <see cref="T:System.DateTime"/> that specifies a
        /// date.
        /// </param>
        /// <returns>An integer giving the day of months, starting with 1.
        /// </returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// The exception is thrown if the
        /// <see cref="T:System.DateTime"/> parameter is not in the
        /// supported range of the Hijri calendar.
        /// </exception>
        public override int GetDayOfMonth(DateTime time)
        {
            int rd = M_FromDateTime(time);

            M_CheckFixedHijri("time", rd);
            return(CCHijriCalendar.day_from_fixed(rd));
        }
        public static void my_from_fixed(out int month, out int year, int date)
        {
            year = CCHijriCalendar.year_from_fixed(date);
            int num = 1 + (int)Math.Ceiling((double)(date - 29 - CCHijriCalendar.fixed_from_dmy(1, 1, year)) / 29.5);

            month = ((num >= 12) ? 12 : num);
        }
        public static int month_from_fixed(int date)
        {
            int result;
            int num;

            CCHijriCalendar.my_from_fixed(out result, out num, date);
            return(result);
        }
示例#8
0
        /// <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 = CCHijriCalendar.fixed_from_dmy(1, month, year);
            int rd2 = CCHijriCalendar.fixed_from_dmy(1, month + 1, year);

            return(rd2 - rd1);
        }
示例#9
0
        /// <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 = CCHijriCalendar.fixed_from_dmy(1, 1, year);
            int rd2 = CCHijriCalendar.fixed_from_dmy(1, 1, year + 1);

            return(rd2 - rd1);
        }
示例#10
0
        /// <summary>Returns a <see cref="T:System.DateTime" /> that is set to the specified date, time, and 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">A year. </param>
        /// <param name="month">An integer from 1 through 12 that represents a month. </param>
        /// <param name="day">An integer from 1 through 29 that represents a day. </param>
        /// <param name="hour">An integer from 0 through 23 that represents an hour. </param>
        /// <param name="minute">An integer from 0 through 59 that represents a minute. </param>
        /// <param name="second">An integer from 0 through 59 that represents a second. </param>
        /// <param name="millisecond">An integer from 0 through 999 that represents a millisecond. </param>
        /// <param name="era">An era. Specify UmAlQuraCalendar.Eras[UmAlQuraCalendar.CurrentEra] or <see cref="F:System.Globalization.UmAlQuraCalendar.UmAlQuraEra" />.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="year" />, <paramref name="month" />, <paramref name="day" />, or <paramref name="era" /> is outside the range supported by the <see cref="T:System.Globalization.UmAlQuraCalendar" /> class.-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. </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 = CCHijriCalendar.fixed_from_dmy(day, month, year);

            return(this.M_ToDateTime(date, hour, minute, second, millisecond));
        }
示例#11
0
        /// <summary>Calculates the number of days in the specified year of the specified era.</summary>
        /// <returns>The number of days in the specified year and era. The number of days is 354 in a common year or 355 in a leap year.</returns>
        /// <param name="year">A year. </param>
        /// <param name="era">An era. Specify UmAlQuraCalendar.Eras[UmAlQuraCalendar.CurrentEra] or <see cref="F:System.Globalization.UmAlQuraCalendar.UmAlQuraEra" />.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="year" /> or <paramref name="era" /> is outside the range supported by the <see cref="T:System.Globalization.UmAlQuraCalendar" /> class. </exception>
        public override int GetDaysInYear(int year, int era)
        {
            this.M_CheckYE(year, ref era);
            int num  = CCHijriCalendar.fixed_from_dmy(1, 1, year);
            int num2 = CCHijriCalendar.fixed_from_dmy(1, 1, year + 1);

            return(num2 - num);
        }
示例#12
0
        /// <summary>Calculates the number of days in the specified month of the specified year and era.</summary>
        /// <returns>The number of days in the specified month in the specified year and era. The return value is 29 in a common year and 30 in a leap year.</returns>
        /// <param name="year">A year. </param>
        /// <param name="month">An integer from 1 through 12 that represents a month. </param>
        /// <param name="era">An era. Specify UmAlQuraCalendar.Eras[UmAlQuraCalendar.CurrentEra] or <see cref="F:System.Globalization.UmAlQuraCalendar.UmAlQuraEra" />.</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="year" />, <paramref name="month" />, or <paramref name="era" /> is outside the range supported by the <see cref="T:System.Globalization.UmAlQuraCalendar" /> class. </exception>
        public override int GetDaysInMonth(int year, int month, int era)
        {
            this.M_CheckYME(year, month, ref era);
            int num  = CCHijriCalendar.fixed_from_dmy(1, month, year);
            int num2 = CCHijriCalendar.fixed_from_dmy(1, month + 1, year);

            return(num2 - num);
        }
        public static int day_from_fixed(int date)
        {
            int result;
            int num;
            int num2;

            CCHijriCalendar.dmy_from_fixed(out result, out num, out num2, date);
            return(result);
        }
示例#14
0
        /// <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>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// The exception is thrown if the
        /// <see cref="T:System.DateTime"/> parameter is not in the
        /// supported range of the Hijri calendar.
        /// </exception>
        public override int GetDayOfYear(DateTime time)
        {
            int rd = M_FromDateTime(time);

            M_CheckFixedHijri("time", rd);
            int year  = CCHijriCalendar.year_from_fixed(rd);
            int rd1_1 = CCHijriCalendar.fixed_from_dmy(1, 1, year);

            return(rd - rd1_1 + 1);
        }
示例#15
0
 internal void M_CheckYMDE(int year, int month, int day, ref int era)
 {
     this.M_CheckYME(year, month, ref era);
     base.M_ArgumentInRange("day", day, 1, this.GetDaysInMonth(year, month, 1));
     if (year == 9666)
     {
         int rdHijri = CCHijriCalendar.fixed_from_dmy(day, month, year);
         this.M_CheckFixedHijri("day", rdHijri);
     }
 }
示例#16
0
        /// <summary>Calculates on which day of the year a specified date occurs.</summary>
        /// <returns>An integer from 1 through 355 that represents the day of the year specified by the <paramref name="time" /> parameter.</returns>
        /// <param name="time">The <see cref="T:System.DateTime" /> to read. 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>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="time" /> is outside the range supported by this calendar. </exception>
        public override int GetDayOfYear(DateTime time)
        {
            int num = this.M_FromDateTime(time);

            this.M_CheckFixedHijri("time", num);
            int year = CCHijriCalendar.year_from_fixed(num);
            int num2 = CCHijriCalendar.fixed_from_dmy(1, 1, year);

            return(num - num2 + 1);
        }
示例#17
0
        /// <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>A
        /// <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 = CCHijriCalendar.fixed_from_dmy(day, month, year);

            return(M_ToDateTime(rd,
                                hour, minute, second, milliseconds));
        }
示例#18
0
 /// <summary>
 /// A protected method checking the calendar day, month, and year
 /// and the era number.
 /// </summary>
 /// <param name="year">An integer representing the calendar year.
 /// </param>
 /// <param name="month">An integer giving the calendar month.
 /// </param>
 /// <param name="day">An integer giving the calendar day.
 /// </param>
 /// <param name="era">The era number.</param>
 /// <exception cref="T:System.ArgumentException">
 /// The exception is thrown if the era is not equal
 /// <see cref="F:HijriEra"/>.
 /// </exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// The exception is thrown if the calendar year, month, or day is
 /// outside of the allowed range.
 /// </exception>
 internal void M_CheckYMDE(int year, int month, int day, ref int era)
 {
     M_CheckYME(year, month, ref era);
     M_ArgumentInRange("day", day, 1,
                       GetDaysInMonth(year, month, HijriEra));
     if (year == 9666)
     {
         int rd = CCHijriCalendar.fixed_from_dmy(day, month,
                                                 year);
         M_CheckFixedHijri("day", rd);
     }
 }
示例#19
0
        /// <summary>Calculates a date that is a specified number of years away from a specified initial date.</summary>
        /// <returns>A <see cref="T:System.DateTime" /> that represents the date yielded by adding the number of years specified by the <paramref name="years" /> 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 years. 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="years">The positive or negative number of years 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="years" /> is less than -10,000 or greater than 10,000. -or-<paramref name="time" /> is outside the range supported by this calendar.</exception>
        public override DateTime AddYears(DateTime time, int years)
        {
            int num = this.M_FromDateTime(time);
            int day;
            int month;
            int num2;

            CCHijriCalendar.dmy_from_fixed(out day, out month, out num2, num);
            num2 += years;
            num   = CCHijriCalendar.fixed_from_dmy(day, month, num2);
            this.M_CheckFixedHijri("time", num);
            return(this.M_ToDateTime(num).Add(time.TimeOfDay));
        }
示例#20
0
 internal void M_CheckYME(int year, int month, ref int era)
 {
     this.M_CheckYE(year, ref era);
     if (month < 1 || month > 12)
     {
         throw new ArgumentOutOfRangeException("month", "Month must be between one and twelve.");
     }
     if (year == 9666)
     {
         int rdHijri = CCHijriCalendar.fixed_from_dmy(1, month, year);
         this.M_CheckFixedHijri("month", rdHijri);
     }
 }
示例#21
0
        /// <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));
        }
示例#22
0
        /// <summary>
        /// Overrideden. 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>
        /// <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 AddYears(DateTime time, int years)
        {
            int rd = M_FromDateTime(time);
            int day, month, year;

            CCHijriCalendar.dmy_from_fixed(
                out day, out month, out year, rd);
            year += years;
            rd    = CCHijriCalendar.fixed_from_dmy(day, month, year);
            M_CheckFixedHijri("time", rd);
            DateTime t = M_ToDateTime(rd);

            return(t.Add(time.TimeOfDay));
        }
示例#23
0
 /// <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(CCHijriCalendar.is_leap_year(year));
 }
 public static void dmy_from_fixed(out int day, out int month, out int year, int date)
 {
     CCHijriCalendar.my_from_fixed(out month, out year, date);
     day = date - CCHijriCalendar.fixed_from_dmy(1, month, year) + 1;
 }
 public static int date_difference(int dayA, int monthA, int yearA, int dayB, int monthB, int yearB)
 {
     return(CCHijriCalendar.fixed_from_dmy(dayB, monthB, yearB) - CCHijriCalendar.fixed_from_dmy(dayA, monthA, yearA));
 }
 public static int day_number(int day, int month, int year)
 {
     return(CCHijriCalendar.date_difference(31, 12, year - 1, day, month, year));
 }
 public static int days_remaining(int day, int month, int year)
 {
     return(CCHijriCalendar.date_difference(day, month, year, 31, 12, year));
 }