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.GetMonthsInYear(y, 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.GetMonthsInYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
[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); } } } }
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(); }
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); }
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); }
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); }
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); } } }
public static void Main() { // Creates and initializes a HebrewCalendar. HebrewCalendar myCal = new HebrewCalendar(); // Checks all the months in five years in the current era. int iMonthsInYear; for (int y = 5761; y <= 5765; y++) { Console.Write("{0}:\t", y); iMonthsInYear = myCal.GetMonthsInYear(y, HebrewCalendar.CurrentEra); for (int m = 1; m <= iMonthsInYear; m++) { Console.Write("\t{0}", myCal.IsLeapMonth(y, m, HebrewCalendar.CurrentEra)); } Console.WriteLine(); } }
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); } } }
private void AddHebDate(RichTextBox month_x_y, DateTime gregDate, bool showYear) { try { string textMonth, textDate; int year = hebCal.GetYear(gregDate); int month = hebCal.GetMonth(gregDate); int day = hebCal.GetDayOfMonth(gregDate); int monthsInYear = hebCal.GetMonthsInYear(year); string[] arrDays = { "א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י", "יא", "יב", "יג", "יד", "טו", "טז", "יז", "יח", "יט", "כ", "כא", "כב", "כג", "כד", "כה", "כו", "כז", "כח", "כט", "ל" }; string[] arrMonths12 = { "תשרי", "חשוון", "כסלו", "טבת", "שבט", "אדר", "ניסן", "אייר", "סיוון", "תמוז", "אב", "אלול" }; string[] arrMonths13 = { "תשרי", "חשוון", "כסלו", "טבת", "שבט", "אדר א", "אדר ב", "ניסן", "אייר", "סיוון", "תמוז", "אב", "אלול" }; if (monthsInYear == 13) { textMonth = arrMonths13[month - 1]; } else { textMonth = arrMonths12[month - 1]; } textDate = arrDays[day - 1] + " " + textMonth; month_x_y.AppendText(Environment.NewLine + textDate); month_x_y.SelectionAlignment = HorizontalAlignment.Right; if (day == 1 || showYear) { month_x_y.AppendText(Environment.NewLine + GetStringHebYear(year)); month_x_y.SelectionAlignment = HorizontalAlignment.Right; //Check for hebYear is in db. if not, let the user know that info might be incorrect. CheckHebYearInDB(year); } } catch (Exception err) { MessageBox.Show("AddHebDate failed\n" + err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }