Exemple #1
0
    public static void Main()
    {
        // Creates and initializes a HebrewCalendar.
        HebrewCalendar myCal = new HebrewCalendar();

        // Displays the header.
        Console.Write("YEAR\t");
        for (int y = 5761; y <= 5765; y++)
        {
            Console.Write("\t{0}", y);
        }
        Console.WriteLine();

        // Displays the value of the CurrentEra property.
        Console.Write("CurrentEra:");
        for (int y = 5761; y <= 5765; y++)
        {
            Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, HebrewCalendar.CurrentEra));
        }
        Console.WriteLine();

        // Displays the values in the Eras property.
        for (int i = 0; i < myCal.Eras.Length; i++)
        {
            Console.Write("Era {0}:\t", myCal.Eras[i]);
            for (int y = 5761; y <= 5765; y++)
            {
                Console.Write("\t{0}", myCal.GetDaysInMonth(y, 2, myCal.Eras[i]));
            }
            Console.WriteLine();
        }
    }
Exemple #2
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);
                    }
                }
            }
        }
        [Test, Timeout(300000)] // Can take a long time under NCrunch.
        public void BclThroughHistory_Civil()
        {
            Calendar bcl  = new HebrewCalendar();
            var      noda = CalendarSystem.GetHebrewCalendar(HebrewMonthNumbering.Civil);

            // 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;

            for (int year = minYear; year <= maxYear; year++)
            {
                int months = bcl.GetMonthsInYear(year);
                Assert.AreEqual(months, noda.GetMaxMonth(year));
                for (int month = 1; month <= months; month++)
                {
                    Assert.AreEqual(bcl.GetDaysInMonth(year, month), noda.GetDaysInMonth(year, month),
                                    "Year: {0}; Month: {1}", year, month);
                    for (int day = 1; day < bcl.GetDaysInMonth(year, month); day++)
                    {
                        DateTime  bclDate  = new DateTime(year, month, day, bcl);
                        LocalDate nodaDate = new LocalDate(year, month, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified());
                        Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate).WithCalendar(noda).Date);
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(month, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                    }
                }
            }
        }
 ///<summary>Gets the length of a Hebrew month.</summary>
 ///<param name="month">The month.</param>
 ///<param name="hebrewYear">The year.</param>
 ///<returns>The number of days in the month.</returns>
 public static int Length(this HebrewMonth month, int hebrewYear)
 {
     if (month == 0)
     {
         throw new ArgumentOutOfRangeException("month", "None is not a valid month.");
     }
     return(calendar.GetDaysInMonth(hebrewYear, month.Index(hebrewYear)));
 }
Exemple #5
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);
        }
Exemple #6
0
    public static void Main()
    {
        StreamWriter output = new StreamWriter("HebrewCalendarInfo.txt");

        // Make the Hebrew Calendar the current calendar and
        // Hebrew (Israel) the current thread culture.
        HebrewCalendar hc      = new HebrewCalendar();
        CultureInfo    culture = CultureInfo.CreateSpecificCulture("he-IL");

        culture.DateTimeFormat.Calendar     = hc;
        Thread.CurrentThread.CurrentCulture = culture;

        output.WriteLine("{0} Information:\n",
                         GetCalendarName(culture.DateTimeFormat.Calendar));

        // Get the calendar range expressed in both Hebrew calendar and
        // Gregorian calendar dates.
        output.WriteLine("Start Date: {0} ", hc.MinSupportedDateTime);
        culture.DateTimeFormat.Calendar = culture.Calendar;
        output.WriteLine("            ({0} Gregorian)\n",
                         hc.MinSupportedDateTime);

        culture.DateTimeFormat.Calendar = hc;
        output.WriteLine("End Date: {0} ", hc.MaxSupportedDateTime);
        culture.DateTimeFormat.Calendar = culture.Calendar;
        output.WriteLine("          ({0} Gregorian)\n",
                         hc.MaxSupportedDateTime);

        culture.DateTimeFormat.Calendar = hc;

        // Get the year in the Hebrew calendar that corresponds to 1/1/2012
        // and display information about it.
        DateTime startOfYear = new DateTime(2012, 1, 1);

        output.WriteLine("Days in the Year {0}: {1}\n",
                         hc.GetYear(startOfYear),
                         hc.GetDaysInYear(hc.GetYear(startOfYear)));

        output.WriteLine("Days in Each Month of {0}:\n", hc.GetYear(startOfYear));
        output.WriteLine("Month       Days       Month Name");
        // Change start of year to first day of first month
        startOfYear = hc.ToDateTime(hc.GetYear(startOfYear), 1, 1, 0, 0, 0, 0);
        DateTime startOfMonth = startOfYear;

        for (int ctr = 1; ctr <= hc.GetMonthsInYear(hc.GetYear(startOfYear)); ctr++)
        {
            output.Write(" {0,2}", ctr);
            output.WriteLine("{0,12}{1,15:MMM}",
                             hc.GetDaysInMonth(hc.GetYear(startOfMonth), hc.GetMonth(startOfMonth)),
                             startOfMonth);
            startOfMonth = hc.AddMonths(startOfMonth, 1);
        }

        output.Close();
    }
Exemple #7
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 static void Main()
    {
        // Creates and initializes a HebrewCalendar.
        HebrewCalendar myCal = new HebrewCalendar();

        // Creates a holder for the last day of the second month (February).
        int iLastDay;

        // Displays the header.
        Console.Write("YEAR\t");
        for (int y = 5761; y <= 5765; y++)
        {
            Console.Write("\t{0}", y);
        }
        Console.WriteLine();

        // Checks five years in the current era.
        Console.Write("CurrentEra:");
        for (int y = 5761; y <= 5765; y++)
        {
            iLastDay = myCal.GetDaysInMonth(y, 2, HebrewCalendar.CurrentEra);
            Console.Write("\t{0}", myCal.IsLeapDay(y, 2, iLastDay, HebrewCalendar.CurrentEra));
        }
        Console.WriteLine();

        // Checks five years in each of the eras.
        for (int i = 0; i < myCal.Eras.Length; i++)
        {
            Console.Write("Era {0}:\t", myCal.Eras[i]);
            for (int y = 5761; y <= 5765; y++)
            {
                iLastDay = myCal.GetDaysInMonth(y, 2, myCal.Eras[i]);
                Console.Write("\t{0}", myCal.IsLeapDay(y, 2, iLastDay, myCal.Eras[i]));
            }
            Console.WriteLine();
        }
    }
Exemple #9
0
        private int GetWeekCountFromSimchatTorah(DateTime currentDate)
        {
            int weekCountFromSimchat;

            weekCountFromSimchat = GetWeekOfHebYear(currentDate) - weeksTillSimchatTorah;
            //if true, currentDate is before simchat torah of its year.
            if (weekCountFromSimchat <= 0)
            {
                int      lastMonth         = hebCal.GetMonthsInYear(hebYear);
                int      lastDay           = hebCal.GetDaysInMonth(hebYear, lastMonth);
                DateTime lastDayOfPrevYear = GetDateTimeHebDate(hebYear, lastMonth, lastDay);
                return(GetWeekOfHebYear(currentDate) + GetWeekCountFromSimchatTorah(lastDayOfPrevYear) - 1);
            }
            return(weekCountFromSimchat);
        }
        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);
                }
            }
        }
Exemple #11
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);
                }
            }
        }
Exemple #12
0
        public static bool IsKislevLong(int year)
        {
            HebrewCalendar hebCal = new HebrewCalendar();

            return(hebCal.GetDaysInMonth(year, 3) == 30);
        }
Exemple #13
0
        public static bool IsCheshvanShort(int year)
        {
            HebrewCalendar hebCal = new HebrewCalendar();

            return(hebCal.GetDaysInMonth(year, 2) == 29);
        }