GetYear() public method

public GetYear ( System.DateTime time ) : int
time System.DateTime
return int
コード例 #1
0
        [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);
                    }
                }
            }
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        [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);
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
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);
        }
コード例 #6
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);
         }
     }
 }
コード例 #7
0
ファイル: LinqTests.cs プロジェクト: ayahc1093/Zmanim
        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;
            }
        }
コード例 #8
0
ファイル: Dates.cs プロジェクト: hozias/yedidim
        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();
        }
コード例 #9
0
ファイル: LinqTests.cs プロジェクト: ayahc1093/Zmanim
        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;
                }
            }
        }
コード例 #10
0
ファイル: CalendarTest.cs プロジェクト: GirlD/mono
	[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);
	}
コード例 #11
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;
 }
コード例 #12
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);
        }
コード例 #13
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);
        }