Ejemplo n.º 1
0
        /// <summary>返回与指定 <see cref="T:System.DateTime" /> 相距指定年数的 <see cref="T:System.DateTime" />。</summary>
        /// <returns>将指定年数添加到指定的 <see cref="T:System.DateTime" /> 中时得到的 <see cref="T:System.DateTime" />。</returns>
        /// <param name="time">
        /// <see cref="T:System.DateTime" />,将向其添加 <paramref name="years" />。</param>
        /// <param name="years">要添加的年数。</param>
        /// <exception cref="T:System.ArgumentException">结果 <see cref="T:System.DateTime" /> 超出了支持的范围。</exception>
        public override DateTime AddYears(DateTime time, int years)
        {
            int datePart = this.GetDatePart(time.Ticks, 0);
            int month    = this.GetDatePart(time.Ticks, 2);
            int day      = this.GetDatePart(time.Ticks, 3);
            int num      = datePart + years;

            HebrewCalendar.CheckHebrewYearValue(num, 0, "years");
            int monthsInYear = this.GetMonthsInYear(num, 0);

            if (month > monthsInYear)
            {
                month = monthsInYear;
            }
            int daysInMonth = this.GetDaysInMonth(num, month);

            if (day > daysInMonth)
            {
                day = daysInMonth;
            }
            long     ticks = this.ToDateTime(num, month, day, 0, 0, 0, 0).Ticks + time.Ticks % 864000000000L;
            DateTime supportedDateTime1 = this.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }
Ejemplo n.º 2
0
        // input: UTC DateTime object
        public DateTime GetIsraelTime(DateTime d)
        {
            d = d.AddHours(2);           // Israel is at GMT+2

            // April 2nd, 2:00 AM
            DateTime DSTStart = new DateTime(d.Year, 4, 2, 2, 0, 0);

            while (DSTStart.DayOfWeek != DayOfWeek.Friday)
            {
                DSTStart = DSTStart.AddDays(-1);
            }

            CultureInfo jewishCulture = CultureInfo.CreateSpecificCulture("he-IL");

            System.Globalization.HebrewCalendar cal =
                new System.Globalization.HebrewCalendar();
            jewishCulture.DateTimeFormat.Calendar = cal;
            // Yom HaKipurim, at the start of the next Jewish year, 2:00 AM
            DateTime DSTFinish =
                new DateTime(cal.GetYear(DSTStart) + 1, 1, 10, 2, 0, 0, cal);

            while (DSTFinish.DayOfWeek != DayOfWeek.Sunday)
            {
                DSTFinish = DSTFinish.AddDays(-1);
            }

            if (d > DSTStart && d < DSTFinish)
            {
                d = d.AddHours(1);
            }

            return(d);
        }
        [Test, Timeout(300000)] // Can take a long time under NCrunch.
        public void BclThroughHistory_Scriptural()
        {
            Calendar bcl = new HebrewCalendar();
            var noda = CalendarSystem.HebrewScriptural;

            // The min supported date/time starts part way through the year
            var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1;
            // The max supported date/time ends part way through the year
            var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1;

            // Can't use BclEquivalenceHelper for this one, because of the month conversions.
            for (int year = minYear; year <= maxYear; year++)
            {
                int months = bcl.GetMonthsInYear(year);
                Assert.AreEqual(months, noda.GetMonthsInYear(year));
                for (int civilMonth = 1; civilMonth <= months; civilMonth++)
                {
                    int scripturalMonth = HebrewMonthConverter.CivilToScriptural(year, civilMonth);
                    Assert.AreEqual(bcl.GetDaysInMonth(year, civilMonth), noda.GetDaysInMonth(year, scripturalMonth),
                        "Year: {0}; Month: {1} (civil)", year, civilMonth);
                    for (int day = 1; day < bcl.GetDaysInMonth(year, civilMonth); day++)
                    {
                        DateTime bclDate = new DateTime(year, civilMonth, day, bcl);
                        LocalDate nodaDate = new LocalDate(year, scripturalMonth, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified(), "{0}-{1}-{2}", year, scripturalMonth, day);
                        Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate, noda).Date);
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(scripturalMonth, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //This function exists as a hack to prevent us from loading all of the non-gregorian
        //calendars unless they're required.
        internal Calendar GetCalendarInstanceRare(int calType)
        {
            BCLDebug.Assert(calType != Calendar.CAL_GREGORIAN, "calType!=Calendar.CAL_GREGORIAN");

            switch (calType)
            {
            case Calendar.CAL_GREGORIAN_US:                   // Gregorian (U.S.) calendar
            case Calendar.CAL_GREGORIAN_ME_FRENCH:            // Gregorian Middle East French calendar
            case Calendar.CAL_GREGORIAN_ARABIC:               // Gregorian Arabic calendar
            case Calendar.CAL_GREGORIAN_XLIT_ENGLISH:         // Gregorian Transliterated English calendar
            case Calendar.CAL_GREGORIAN_XLIT_FRENCH:          // Gregorian Transliterated French calendar
                return(new GregorianCalendar((GregorianCalendarTypes)calType));

            case Calendar.CAL_TAIWAN:                         // Taiwan Era calendar
                return(TaiwanCalendar.GetDefaultInstance());

            case Calendar.CAL_JAPAN:                          // Japanese Emperor Era calendar
                return(JapaneseCalendar.GetDefaultInstance());

            case Calendar.CAL_KOREA:                          // Korean Tangun Era calendar
                return(KoreanCalendar.GetDefaultInstance());

            case Calendar.CAL_HIJRI:                          // Hijri (Arabic Lunar) calendar
                return(HijriCalendar.GetDefaultInstance());

            case Calendar.CAL_THAI:                           // Thai calendar
                return(ThaiBuddhistCalendar.GetDefaultInstance());

            case Calendar.CAL_HEBREW:                         // Hebrew (Lunar) calendar
                return(HebrewCalendar.GetDefaultInstance());
            }
            return(GregorianCalendar.GetDefaultInstance());
        }
Ejemplo n.º 5
0
 private static void CheckHebrewYearValue(int y, int era, string varName)
 {
     HebrewCalendar.CheckEraRange(era);
     if (y > 5999 || y < 5343)
     {
         throw new ArgumentOutOfRangeException(varName, string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), (object)5343, (object)5999));
     }
 }
Ejemplo n.º 6
0
        internal virtual int GetDatePart(long ticks, int part)
        {
            HebrewCalendar.CheckTicksRange(ticks);
            DateTime dateTime = new DateTime(ticks);
            int      year     = dateTime.Year;
            int      month    = dateTime.Month;
            int      day      = dateTime.Day;

            HebrewCalendar.__DateBuffer lunarDate = new HebrewCalendar.__DateBuffer();
            lunarDate.year = year + 3760;
            int index1 = HebrewCalendar.GetLunarMonthDay(year, lunarDate);

            HebrewCalendar.__DateBuffer result = new HebrewCalendar.__DateBuffer();
            result.year  = lunarDate.year;
            result.month = lunarDate.month;
            result.day   = lunarDate.day;
            long absoluteDate = GregorianCalendar.GetAbsoluteDate(year, month, day);

            if (month == 1 && day == 1)
            {
                return(HebrewCalendar.GetResult(result, part));
            }
            long num1 = absoluteDate - GregorianCalendar.GetAbsoluteDate(year, 1, 1);

            if (num1 + (long)lunarDate.day <= (long)HebrewCalendar.LunarMonthLen[index1, lunarDate.month])
            {
                result.day += (int)num1;
                return(HebrewCalendar.GetResult(result, part));
            }
            ++result.month;
            result.day = 1;
            long num2 = num1 - (long)(HebrewCalendar.LunarMonthLen[index1, lunarDate.month] - lunarDate.day);

            if (num2 > 1L)
            {
                while (num2 > (long)HebrewCalendar.LunarMonthLen[index1, result.month])
                {
                    long num3 = num2;
                    int[,] numArray = HebrewCalendar.LunarMonthLen;
                    int index2 = index1;
                    HebrewCalendar.__DateBuffer dateBuffer = result;
                    int num4 = dateBuffer.month;
                    int num5 = num4 + 1;
                    dateBuffer.month = num5;
                    int  index3 = num4;
                    long num6   = (long)numArray[index2, index3];
                    num2 = num3 - num6;
                    if (result.month > 13 || HebrewCalendar.LunarMonthLen[index1, result.month] == 0)
                    {
                        ++result.year;
                        index1       = HebrewCalendar.HebrewTable[(year + 1 - 1583) * 2 + 1];
                        result.month = 1;
                    }
                }
                result.day += (int)(num2 - 1L);
            }
            return(HebrewCalendar.GetResult(result, part));
        }
Ejemplo n.º 7
0
        /// <summary>返回一个 <see cref="T:System.DateTime" />,它设置为指定纪元中的指定日期和时间。</summary>
        /// <returns>设置为当前纪元中的指定日期和时间的 <see cref="T:System.DateTime" />。</returns>
        /// <param name="year">表示年份的整数。</param>
        /// <param name="month">1 到 13 之间的一个整数,它表示月份。</param>
        /// <param name="day">1 到 30 之间的一个整数,它表示天。</param>
        /// <param name="hour">0 与 23 之间的一个整数,它表示小时。</param>
        /// <param name="minute">0 与 59 之间的一个整数,它表示分钟。</param>
        /// <param name="second">0 与 59 之间的一个整数,它表示秒。</param>
        /// <param name="millisecond">0 与 999 之间的一个整数,它表示毫秒。</param>
        /// <param name="era">表示纪元的整数。指定 <see cref="F:System.Globalization.HebrewCalendar.HebrewEra" /> 或 HebrewCalendar.Eras[Calendar.CurrentEra]。</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="year" />、<paramref name="month" />、<paramref name="day" /> 或 <paramref name="era" /> 超出了当前 <see cref="T:System.Globalization.HebrewCalendar" /> 对象支持的范围。- 或 -<paramref name="hour" /> 小于 0 或大于 23。- 或 -<paramref name="minute" /> 小于 0 或大于 59。- 或 -<paramref name="second" /> 小于 0 或大于 59。- 或 -<paramref name="millisecond" /> 小于 0 或大于 999。</exception>
        public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
        {
            HebrewCalendar.CheckHebrewYearValue(year, era, "year");
            this.CheckHebrewMonthValue(year, month, era);
            this.CheckHebrewDayValue(year, month, day, era);
            DateTime gregorian = HebrewCalendar.HebrewToGregorian(year, month, day, hour, minute, second, millisecond);

            HebrewCalendar.CheckTicksRange(gregorian.Ticks);
            return(gregorian);
        }
Ejemplo n.º 8
0
 static void Main()
 {
     var dtfi = new CultureInfo("he-IL").DateTimeFormat;
     var calendar = new HebrewCalendar();
     dtfi.Calendar = calendar;
     var lines = from year in Enumerable.Range(5775, 2)
                 from month in Enumerable.Range(1, calendar.GetMonthsInYear(year))
                 select string.Format(dtfi,
                     "{0}-{1}: {2:MMMM}", year, month, new DateTime(year, month, 1, calendar));
     FormHelper.ShowText(lines);
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,CalendarName,TwoDigitYearMax")] System.Globalization.HebrewCalendar hebrewCalendar)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hebrewCalendar);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hebrewCalendar));
        }
Ejemplo n.º 10
0
        /// <summary>返回指定纪元中指定年份的天数。</summary>
        /// <returns>指定纪元中指定年份的天数。</returns>
        /// <param name="year">表示年份的整数。</param>
        /// <param name="era">表示纪元的整数。指定 <see cref="F:System.Globalization.HebrewCalendar.HebrewEra" /> 或 HebrewCalendar.Eras[Calendar.CurrentEra]。</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="year" /> 或 <paramref name="era" /> 超出了当前 <see cref="T:System.Globalization.HebrewCalendar" /> 对象支持的范围。</exception>
        public override int GetDaysInYear(int year, int era)
        {
            HebrewCalendar.CheckEraRange(era);
            int hebrewYearType = HebrewCalendar.GetHebrewYearType(year, era);

            if (hebrewYearType < 4)
            {
                return(352 + hebrewYearType);
            }
            return(382 + (hebrewYearType - 3));
        }
        public void DaysInYear()
        {
            var bcl = new HebrewCalendar();
            var minYear = bcl.GetYear(bcl.MinSupportedDateTime);
            var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime);

            for (int year = minYear; year <= maxYear; year++)
            {
                Assert.AreEqual(bcl.GetDaysInYear(year), HebrewScripturalCalculator.DaysInYear(year));
            }
        }
Ejemplo n.º 12
0
        public IEnumerable<ComplexZmanimCalendar> GetDaysInHebrewMonth(DateTime yearAndMonth, GeoLocation location)
        {
            Calendar calendar = new HebrewCalendar();
            var daysInMonth = calendar.GetDaysInMonth(calendar.GetYear(yearAndMonth), calendar.GetMonth(yearAndMonth));

            for (int i = 0; i < daysInMonth; i++)
            {
                var zmanimCalendar = new ComplexZmanimCalendar(location);
                zmanimCalendar.DateWithLocation.Date = new DateTime(yearAndMonth.Year, yearAndMonth.Month, i + 1);
                yield return zmanimCalendar;
            }
        }
        public void IsLeapYear()
        {
            var bcl = new HebrewCalendar();
            var minYear = bcl.GetYear(bcl.MinSupportedDateTime);
            var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime);
            var noda = CalendarSystem.HebrewCivil;

            for (int year = minYear; year <= maxYear; year++)
            {
                Assert.AreEqual(bcl.IsLeapYear(year), noda.IsLeapYear(year));
            }
        }
        [Test, Timeout(300000)] // Can take a long time under NCrunch.
        public void BclThroughHistory_Civil()
        {
            Calendar bcl = new HebrewCalendar();
            var noda = CalendarSystem.HebrewCivil;

            // The min supported date/time starts part way through the year
            var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1;
            // The max supported date/time ends part way through the year
            var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1;

            BclEquivalenceHelper.AssertEquivalent(bcl, noda, minYear, maxYear);
        }
Ejemplo n.º 15
0
        public void WhenYearMonthDayCalendarPassedIntoConstructor_ExpectSameValueReturned()
        {
            // Arrange
            var calendar = new HebrewCalendar();
            var expected = new DateTime(5776, 8, 17, calendar);

            // Act
            var target = new DateTimeWrap(5776, 8, 17, calendar);
            var actual = target.DateTimeInstance;

            // Assert
            actual.Should().Equal(expected);
        }
Ejemplo n.º 16
0
        /// <summary>返回指定纪元中指定年份的指定月份的天数。</summary>
        /// <returns>指定纪元中指定年份的指定月份中的天数。</returns>
        /// <param name="year">表示年份的整数。</param>
        /// <param name="month">1 到 13 之间的一个整数,它表示月份。</param>
        /// <param name="era">表示纪元的整数。指定 <see cref="F:System.Globalization.HebrewCalendar.HebrewEra" /> 或 Calendar.Eras[Calendar.CurrentEra]。</param>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="year" />、<paramref name="month" /> 或 <paramref name="era" /> 超出了当前 <see cref="T:System.Globalization.HebrewCalendar" /> 对象支持的范围。</exception>
        public override int GetDaysInMonth(int year, int month, int era)
        {
            HebrewCalendar.CheckEraRange(era);
            int hebrewYearType = HebrewCalendar.GetHebrewYearType(year, era);

            this.CheckHebrewMonthValue(year, month, era);
            int num = HebrewCalendar.LunarMonthLen[hebrewYearType, month];

            if (num != 0)
            {
                return(num);
            }
            throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month"));
        }
Ejemplo n.º 17
0
        private static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
        {
            int num = hebrewYear - 3760;

            HebrewCalendar.__DateBuffer lunarDate = new HebrewCalendar.__DateBuffer();
            int lunarMonthDay = HebrewCalendar.GetLunarMonthDay(num, lunarDate);

            if (hebrewMonth == lunarDate.month && hebrewDay == lunarDate.day)
            {
                return(new DateTime(num, 1, 1, hour, minute, second, millisecond));
            }
            int dayDifference = HebrewCalendar.GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, lunarDate.month, lunarDate.day);

            return(new DateTime(new DateTime(num, 1, 1).Ticks + (long)dayDifference * 864000000000L + Calendar.TimeToTicks(hour, minute, second, millisecond)));
        }
Ejemplo n.º 18
0
 static void Main()
 {
     var dtfi = new CultureInfo("he-IL").DateTimeFormat;
     var calendar = new HebrewCalendar();
     dtfi.Calendar = calendar;
     dtfi.MonthNames = new[] {
         "Tishri", "Heshvan", "Kislev", "Tevet",
         "Shevat", "Adar", "Adar II", "Nisan", "Iyar", "Sivan", "Tamuz",
         "Av", "Elul"
     };
     var lines = from year in Enumerable.Range(5775, 2)
                 from month in Enumerable.Range(1, calendar.GetMonthsInYear(year))
                 select string.Format(dtfi,
                     "{0}-{1}: {2:MMMM}", year, month, new DateTime(year, month, 1, calendar));
     FormHelper.ShowText(lines);
 }
Ejemplo n.º 19
0
        public Dates()
        {
            hebCal = new HebrewCalendar();
            DateTime dt = DateTime.Now;
            NextGregMonth = 0;
            CurrentGregDay = dt.Day;
            CurrentGregMonth = dt.Month;
            CurrentGregYear = dt.Year;
            GetGregDateScope();

            NextJewishMonth = 0;
            //NextJewishMonthScope = 0;
            CurrentJewishDay = hebCal.GetDayOfMonth(dt);
            CurrentJewishMonth = hebCal.GetMonth(dt);
            CurrentJewishYear = hebCal.GetYear(dt);
            GetJewishDaysScope();
        }
Ejemplo n.º 20
0
 public static void HebrewTest()
 {
     Calendar hCal = new HebrewCalendar();
     DateTime dTest = hCal.ToDateTime(5360, 04, 14, 0, 0, 0, 0);
     Assert.True(dTest.Equals(new DateTime(1600, 1, 1)));
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         dTest = hCal.ToDateTime(0, 03, 25, 0, 0, 0, 0);
     });
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         dTest = hCal.ToDateTime(10000, 03, 25, 0, 0, 0, 0);
     });
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         dTest = hCal.ToDateTime(5000, 0, 25, 0, 0, 0, 0);
     });
 }
 public void DaysInMonth()
 {
     var bcl = new HebrewCalendar();
     // Not all months in the min/max years are supported
     var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1;
     var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1;
     
     for (int year = minYear; year <= maxYear; year++)
     {
         int months = bcl.GetMonthsInYear(year);
         for (int month = 1; month <= months; month++)
         {
             int scripturalMonth = HebrewMonthConverter.CivilToScriptural(year, month);
             int bclDays = bcl.GetDaysInMonth(year, month);
             int nodaDays = HebrewScripturalCalculator.DaysInMonth(year, scripturalMonth);
             Assert.AreEqual(bclDays, nodaDays);
         }
     }
 }
Ejemplo n.º 22
0
        public IEnumerable<ComplexZmanimCalendar> GetDaysInHebrewYear(DateTime year, GeoLocation location)
        {
            Calendar calendar = new HebrewCalendar();
            var currentYear = calendar.GetYear(year);
            var amountOfMonths = calendar.GetMonthsInYear(currentYear);

            for (int i = 0; i < amountOfMonths; i++)
            {
                var currentMonth = i + 1;
                var daysInMonth = calendar.GetDaysInMonth(currentYear, currentMonth);

                for (int dayOfMonth = 0; dayOfMonth < daysInMonth; dayOfMonth++)
                {
                    var zmanimCalendar = new ComplexZmanimCalendar(location);
                    zmanimCalendar.DateWithLocation.Date = new DateTime(currentYear, currentMonth, dayOfMonth + 1, calendar);
                    yield return zmanimCalendar;
                }
            }
        }
Ejemplo n.º 23
0
	protected override void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
	}
Ejemplo n.º 24
0
        /// <summary>
        /// GetCalendar returns a .NET Calendar equivalent to a CLDR Calendar
        /// </summary>
        /// <param name="calendar">A CLDR Calendar</param>
        /// <returns>A .NET Calendar</returns>
        private static System.Globalization.Calendar GetCalendar(Types.Calendar calendar)
        {
            System.Globalization.Calendar dotNetCalendar = null;

            if (string.Compare(calendar.Id, "gregorian", StringComparison.InvariantCulture) == 0 && calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                dotNetCalendar = new GregorianCalendar();
            }
            else if (string.Compare(calendar.Id, "japanese", StringComparison.InvariantCulture) == 0)
            {
                if (calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
                {
                    dotNetCalendar = new JapaneseCalendar();
                }
                else if (calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
                {
                    dotNetCalendar = new JapaneseLunisolarCalendar();
                }
            }
            else if (string.Compare(calendar.Id, "islamic-civil", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HijriCalendar();
            }
            else if (string.Compare(calendar.Id, "islamic", StringComparison.InvariantCulture) == 0
                && calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HijriCalendar();
            }
            else if (string.Compare(calendar.Id, "chinese", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new ChineseLunisolarCalendar();
            }
            else if (string.Compare(calendar.Id, "hebrew", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.LunisolarCalendar)
            {
                dotNetCalendar = new HebrewCalendar();
            }
            else if (string.Compare(calendar.Id, "buddhist", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                dotNetCalendar = new ThaiBuddhistCalendar();
            }
            else if (string.Compare(calendar.Id, "coptic", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "persian", StringComparison.InvariantCulture) == 0 &&
                calendar.CalendarType.CalendarAlgorithmType == CalendarAlgorithmType.SolarCalendar)
            {
                return new PersianCalendar();
            }
            else if (string.Compare(calendar.Id, "ethiopic", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "indian", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }
            else if (string.Compare(calendar.Id, "roc", StringComparison.InvariantCulture) == 0)
            {
                return null;
            }

            return dotNetCalendar;
        }
Ejemplo n.º 25
0
	public void TestToFourDigitYear2 ()
	{
		GregorianCalendar gc = new GregorianCalendar ();
		Assert.AreEqual (2029, gc.ToFourDigitYear (29), "#1-1");
		Assert.AreEqual (1930, gc.ToFourDigitYear (30), "#1-2");
		Assert.AreEqual (2029, gc.ToFourDigitYear (2029), "#1-3");
		Assert.AreEqual (2030, gc.ToFourDigitYear (2030), "#1-4");

		HebrewCalendar hbc = new HebrewCalendar ();
		Assert.AreEqual (5790, hbc.ToFourDigitYear (90), "#2-1");
		Assert.AreEqual (5691, hbc.ToFourDigitYear (91), "#2-2");
		Assert.AreEqual (5790, hbc.ToFourDigitYear (5790), "#2-3");
		Assert.AreEqual (5691, hbc.ToFourDigitYear (5691), "#2-4");
		Assert.AreEqual (5999, hbc.ToFourDigitYear (5999), "#2-5");
		// LAMESPEC: .NET fails to throw an exception unlike documented
		/*
		try {
			hbc.ToFourDigitYear (6000);
			Assert.Fail ("#2-6");
		} catch (ArgumentOutOfRangeException) {
		}
		*/

		ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
		Assert.AreEqual (2572, tc.ToFourDigitYear (72), "#3-1");
		Assert.AreEqual (2473, tc.ToFourDigitYear (73), "#3-2");
		Assert.AreEqual (2572, tc.ToFourDigitYear (2572), "#3-3");
		Assert.AreEqual (2573, tc.ToFourDigitYear (2573), "#3-4");
		Assert.AreEqual (9999, tc.ToFourDigitYear (9999), "#3-5");
		// LAMESPEC: .NET fails to throw an exception unlike documented
		/*
		try {
			tc.ToFourDigitYear (10000);
			Assert.Fail ("#3-6");
		} catch (ArgumentOutOfRangeException) {
		}
		*/

		KoreanCalendar kc = new KoreanCalendar ();
		Assert.AreEqual (4362, kc.ToFourDigitYear (62), "#4-1");
		Assert.AreEqual (4263, kc.ToFourDigitYear (63), "#4-2");
		Assert.AreEqual (4362, kc.ToFourDigitYear (4362), "#4-3");
		Assert.AreEqual (4363, kc.ToFourDigitYear (4363), "#4-4");
	}
Ejemplo n.º 26
0
	public void GetLeapMonth ()
	{
		GregorianCalendar gc = new GregorianCalendar ();
		Assert.AreEqual (0, gc.GetLeapMonth (2007), "#1-1");
		Assert.AreEqual (0, gc.GetLeapMonth (2008), "#1-2");
		Assert.AreEqual (0, gc.GetLeapMonth (2100), "#1-3");
		Assert.AreEqual (0, gc.GetLeapMonth (2000), "#1-4");

		JulianCalendar jc = new JulianCalendar ();
		Assert.AreEqual (0, jc.GetLeapMonth (2007), "#2-1");
		Assert.AreEqual (0, jc.GetLeapMonth (2008), "#2-2");
		Assert.AreEqual (0, jc.GetLeapMonth (2100), "#2-3");
		Assert.AreEqual (0, jc.GetLeapMonth (2000), "#2-4");
		Assert.AreEqual (0, jc.GetLeapMonth (2009), "#2-5");
		Assert.AreEqual (0, jc.GetLeapMonth (2010), "#2-6");

		HebrewCalendar hc = new HebrewCalendar ();
		// 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap.
		// 5339 % 19 = 0.
		Assert.AreEqual (0, hc.GetLeapMonth (5343), "#3-1");
		Assert.AreEqual (0, hc.GetLeapMonth (5344), "#3-2");
		Assert.AreEqual (7, hc.GetLeapMonth (5345), "#3-3");
		Assert.AreEqual (0, hc.GetLeapMonth (5346), "#3-4");
		Assert.AreEqual (7, hc.GetLeapMonth (5347), "#3-5");
		Assert.AreEqual (0, hc.GetLeapMonth (5348), "#3-6");
		Assert.AreEqual (0, hc.GetLeapMonth (5349), "#3-7");

		ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
		Assert.AreEqual (0, tc.GetLeapMonth (2520), "#4-1");
		Assert.AreEqual (0, tc.GetLeapMonth (2521), "#4-2");
		Assert.AreEqual (0, tc.GetLeapMonth (2522), "#4-3");
		Assert.AreEqual (0, tc.GetLeapMonth (2523), "#4-4");

		ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar ();
		Assert.AreEqual (0, cc.GetLeapMonth (2000), "#5-1");
		Assert.AreEqual (5, cc.GetLeapMonth (2001), "#5-2");
		Assert.AreEqual (0, cc.GetLeapMonth (2002), "#5-3");
		Assert.AreEqual (0, cc.GetLeapMonth (2003), "#5-4");
		Assert.AreEqual (3, cc.GetLeapMonth (2004), "#5-5");
		Assert.AreEqual (0, cc.GetLeapMonth (2005), "#5-6");
		Assert.AreEqual (8, cc.GetLeapMonth (2006), "#5-7");
		Assert.AreEqual (0, cc.GetLeapMonth (2007), "#5-8");
		Assert.AreEqual (0, cc.GetLeapMonth (2008), "#5-9");
		Assert.AreEqual (6, cc.GetLeapMonth (2009), "#5-10");
		Assert.AreEqual (0, cc.GetLeapMonth (2010), "#5-11");
		Assert.AreEqual (0, cc.GetLeapMonth (2011), "#5-12");
		Assert.AreEqual (5, cc.GetLeapMonth (2012), "#5-13");
		Assert.AreEqual (0, cc.GetLeapMonth (2013), "#5-14");
		Assert.AreEqual (10, cc.GetLeapMonth (2014), "#5-15");
		Assert.AreEqual (0, cc.GetLeapMonth (2015), "#5-16");
		Assert.AreEqual (0, cc.GetLeapMonth (2016), "#5-17");
		Assert.AreEqual (7, cc.GetLeapMonth (2017), "#5-18");
		Assert.AreEqual (0, cc.GetLeapMonth (2018), "#5-19");
		Assert.AreEqual (0, cc.GetLeapMonth (2019), "#5-20");

		KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar ();
		Assert.AreEqual (0, kc.GetLeapMonth (2000), "#6-1");
		Assert.AreEqual (5, kc.GetLeapMonth (2001), "#6-2");
		Assert.AreEqual (0, kc.GetLeapMonth (2002), "#6-3");
		Assert.AreEqual (0, kc.GetLeapMonth (2003), "#6-4");
		Assert.AreEqual (3, kc.GetLeapMonth (2004), "#6-5");
		Assert.AreEqual (0, kc.GetLeapMonth (2005), "#6-6");
		Assert.AreEqual (8, kc.GetLeapMonth (2006), "#6-7");
		Assert.AreEqual (0, kc.GetLeapMonth (2007), "#6-8");
		Assert.AreEqual (0, kc.GetLeapMonth (2008), "#6-9");
		Assert.AreEqual (6, kc.GetLeapMonth (2009), "#6-10");
		Assert.AreEqual (0, kc.GetLeapMonth (2010), "#6-11");
		Assert.AreEqual (0, kc.GetLeapMonth (2011), "#6-12");
		Assert.AreEqual (4, kc.GetLeapMonth (2012)); // off from cn by 1, "#6-13");
		Assert.AreEqual (0, kc.GetLeapMonth (2013), "#6-14");
		Assert.AreEqual (10, kc.GetLeapMonth (2014), "#6-15");
		Assert.AreEqual (0, kc.GetLeapMonth (2015), "#6-16");
		Assert.AreEqual (0, kc.GetLeapMonth (2016), "#6-17");
		Assert.AreEqual (6, kc.GetLeapMonth (2017)); // off from cn by 1, "#6-18");
		Assert.AreEqual (0, kc.GetLeapMonth (2018), "#6-19");
		Assert.AreEqual (0, kc.GetLeapMonth (2019), "#6-20");
	}
Ejemplo n.º 27
0
	[Test] // wrt bug #76252.
	public void HebrewCalendarGetDaysInMonth ()
	{
		HebrewCalendar c = new HebrewCalendar ();
		int year = c.GetYear (new DateTime (2005, 9, 1));
		Assert.AreEqual (5765, year);
		int days = c.GetDaysInMonth (year, 13, 1);
		Assert.AreEqual (29, days);
	}
Ejemplo n.º 28
0
 internal static int GetHebrewYearType(int year, int era)
 {
     HebrewCalendar.CheckHebrewYearValue(year, era, "year");
     return(HebrewCalendar.HebrewTable[(year - 3760 - 1583) * 2 + 1]);
 }
Ejemplo n.º 29
0
        public override string ToString()
        {
            //The following bloc ensures that people die in the past.
            HebrewCalendar hc = new HebrewCalendar();
            DateTime d = DateTime.Today;
            int year = (hc.IsLeapYear(hc.GetYear(d))) ? 5774 : 5773;
            year = CheckPrefernce() ? year : yearH;

            return String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3} {4}\",\"{5}\",\"{6}\",\"{7}\",\"0\"",
                plaqueNum1, plaqueNum2, plaqueNum3, nameF, nameL, dayH, monthH, year);
        }
Ejemplo n.º 30
0
        public static Calendar CalendarFromString(
            string                                      name
        )
        {
            Calendar                                    c;

            if (name == null)
            {
                name = String.Empty;
            }

            switch (name.ToLower())
            {
                case "hebrew":
                    c = new HebrewCalendar();
                    break;

                case "hijri":
                    c = new HijriCalendar();
                    break;

                case "japanese":
                    c = new JapaneseCalendar();
                    break;

                case "korean":
                    c = new KoreanCalendar();
                    break;

                case "taiwan":
                    c = new TaiwanCalendar();
                    break;

                case "thaibuddhist":
                    c = new ThaiBuddhistCalendar();
                    break;

                case "umalqura":
                    c = new UmAlQuraCalendar();
                    break;
#if !SILVERLIGHT
                case "persian":
                    c = new PersianCalendar();
                    break;
#endif 
                default:
                    c = new GregorianCalendar();
                    break;
            }

            return c;
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Calculates the Hebrew date of the English anniversary of the person's death for this English year
        /// </summary>
        public void ConvertToHebrew(bool useEnglish)
        {
            int year = useEnglish ? currentYearG : yearG;
            GregorianCalendar gc = new GregorianCalendar(GregorianCalendarTypes.USEnglish);
            HebrewCalendar hc = new HebrewCalendar();
            deathdateG = new DateTime(year, monthG, dayG, gc);

            yearH = hc.GetYear(deathdateG);
            monthH = CorrectedHebrewMonth(deathdateG);
            dayH = hc.GetDayOfMonth(deathdateG);
        }
Ejemplo n.º 32
0
	protected void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
#if NET_2_0
		clcal = new ChineseLunisolarCalendar ();
		tlcal = new TaiwanLunisolarCalendar ();
		jlcal = new JapaneseLunisolarCalendar ();
		klcal = new KoreanLunisolarCalendar ();
#endif
	}
Ejemplo n.º 33
0
        public void WhenYearMonthDayHoursMinutesSecondsMillisecondCalendarKindPassedIntoConstructor_ExpectSameValueReturned()
        {
            // Arrange
            var calendar = new HebrewCalendar();
            DateTimeKind expectedKind = DateTimeKind.Local;
            var expected = new DateTime(5776, 8, 17, 23, 15, 15, 151, calendar, expectedKind);

            // Act
            var target = new DateTimeWrap(5776, 8, 17, 23, 15, 15, 151, calendar, expectedKind);
            var actual = target.DateTimeInstance;

            // Assert
            actual.Should().Equal(expected);
            expectedKind.Should().Equal(actual.Kind);
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Converts from Microsoft's Hebrew month numbering system to usual Hebrew month numbering system
 /// The Hebrew calendar begins on the first day of the seventh month
 /// To illustrate this problem:
 /// Microsoft says since Tishrei is the first month of the new year it is number 1
 /// However, Tishrei is normally number 7
 /// </summary>
 /// <param name="d">A DateTime</param>
 /// <returns>The corrected month number</returns>
 public int CorrectedHebrewMonth(DateTime d)
 {
     HebrewCalendar hc = new HebrewCalendar();
     int zeroCountMonth = hc.GetMonth(d) - 1;//having my months be zero count allows for modulo division
     
     if (hc.IsLeapYear(hc.GetYear(d))){
         zeroCountMonth = (zeroCountMonth + 6) % 13;
     }
     else
     {
         zeroCountMonth = (zeroCountMonth + 6) % 12;
     }
     return zeroCountMonth + 1;
 }
Ejemplo n.º 35
0
 /// <summary>确定指定纪元中的指定年份是否为闰年。</summary>
 /// <returns>如果指定的年是闰年,则为 true;否则为 false。</returns>
 /// <param name="year">表示年份的整数。</param>
 /// <param name="era">表示纪元的整数。指定 <see cref="F:System.Globalization.HebrewCalendar.HebrewEra" /> 或 HebrewCalendar.Eras[Calendar.CurrentEra]。</param>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 /// <paramref name="year" /> 或 <paramref name="era" /> 超出了此日历支持的范围。</exception>
 public override bool IsLeapYear(int year, int era)
 {
     HebrewCalendar.CheckHebrewYearValue(year, era, "year");
     return((7L * (long)year + 1L) % 19L < 7L);
 }
Ejemplo n.º 36
0
 public void Setup()
 {
     hebrewCalendar = new HebrewCalendar();
     gregorianCalendar = new GregorianCalendar();
 }
Ejemplo n.º 37
0
 public static void HebrewTest()
 {
     HebrewCalendar cal = new HebrewCalendar();
     Assert.False(cal.IsLeapMonth(5343, 4));
 }
Ejemplo n.º 38
0
        public DateTimeFormatter(string dateTimePattern, string calendarName, string amDesignator, string pmDesignator)
        {
            Calendar calendar = null;
            switch (calendarName)
            {
                case "ChineseLunisolarCalendar":
                    calendar = new ChineseLunisolarCalendar();
                    break;

                case "GregorianCalendar":
                    calendar = new GregorianCalendar();
                    break;

                case "HebrewCalendar":
                    calendar = new HebrewCalendar();
                    break;

                case "HijriCalendar":
                    calendar = new HijriCalendar();
                    break;

                case "JapaneseCalendar":
                    calendar = new JapaneseCalendar();
                    break;

                case "JapaneseLunisolarCalendar":
                    calendar = new JapaneseLunisolarCalendar();
                    break;

                case "JulianCalendar":
                    calendar = new JulianCalendar();
                    break;

                case "KoreanCalendar":
                    calendar = new KoreanCalendar();
                    break;

                case "KoreanLunisolarCalendar":
                    calendar = new KoreanLunisolarCalendar();
                    break;

                case "PersianCalendar":
                    calendar = new PersianCalendar();
                    break;

                case "TaiwanCalendar":
                    calendar = new TaiwanCalendar();
                    break;

                case "TaiwanLunisolarCalendar":
                    calendar = new TaiwanLunisolarCalendar();
                    break;

                case "ThaiBuddhistCalendar":
                    calendar = new ThaiBuddhistCalendar();
                    break;

                case "UmAlQuraCalendar":
                    calendar = new UmAlQuraCalendar();
                    break;
            }

            Initialize(dateTimePattern, calendar, amDesignator, pmDesignator);
        }