private void SetHebAnnualsOnDate(DateTime date, ref int[] ids, ref bool[] isAnnuals, ref string[] events) { HebrewCalendar hebDate = new HebrewCalendar(); int month = hebDate.GetMonth(date), day = hebDate.GetDayOfMonth(date); OleDbCommand datacommand = new OleDbCommand(); datacommand.Connection = dataConnection; datacommand.CommandText = "SELECT *" + "FROM tblAnnuals " + "WHERE annualGregorian = false AND annualMonth= " + month + " AND annualDay = " + day + " " + "ORDER BY annualID"; OleDbDataReader dataReader = datacommand.ExecuteReader(); while (dataReader.Read()) { int annualID = dataReader.GetInt32(0); string annualName = dataReader.GetString(2); if (index == ids.Length) { ResizeArrays(ref ids, ref events, ref isAnnuals, ids.Length + 1); } ids[index] = annualID; isAnnuals[index] = true; events[index++] = annualName; } dataReader.Close(); }
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(); // Checks five years in the current era. Console.Write("CurrentEra:"); for (int y = 5761; y <= 5765; y++) { Console.Write("\t{0}", myCal.IsLeapYear(y, 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++) { Console.Write("\t{0}", myCal.IsLeapYear(y, myCal.Eras[i])); } Console.WriteLine(); } }
public static Calendar GetCalendar(CalendarTypes calendartype) { Calendar cal; switch (calendartype) { case CalendarTypes.Chinese: cal = new ChineseLunisolarCalendar(); break; case CalendarTypes.Gregorian: cal = new GregorianCalendar(); break; case CalendarTypes.Hebrew: cal = new HebrewCalendar(); break; case CalendarTypes.Islamic: cal = new HijriCalendar(); break; case CalendarTypes.Persian: cal = new PersianCalendar(); break; default: throw new Exception("Calendar not Supported!"); } return(cal); }
public static string GetHebrewDate(DateTime gregorianDate) { Calendar HebCal = new HebrewCalendar(); string hebrewDate = $"{HebCal.GetYear(gregorianDate)}-{HebCal.GetMonth(gregorianDate)}-{HebCal.GetDayOfMonth(gregorianDate)}"; return(hebrewDate); }
/// <summary> /// מחשב האם התאריך בטווח התאריכים בהתחשב בנתוני לוח עברי : שנה מעוברת ,שנים מלאות ,חסרות וכסדרן /// </summary> /// <param name="value">date to check(today)</param> /// <param name="date">date of event</param> /// <param name="length">how meny days is event</param> /// <returns></returns> public static bool IsInRange(this DateTime value, DateTime date, int length) { length--; HebrewCalendar hd = new HebrewCalendar(); //case 1: The same type of year if (hd.GetDaysInYear(hd.GetYear(value)) == hd.GetDaysInYear(hd.GetYear(date))) { //לא נכון למקרה הזה יכול להיות שימושי במקרים אחרים //if (hd.GetDayOfYear(date) + length > hd.GetDaysInYear(hd.GetYear(date))) // length += hd.GetDaysInYear(hd.GetYear(date)); if (hd.GetDayOfYear(value) >= hd.GetDayOfYear(date) && (hd.GetDayOfYear(value) <= (hd.GetDayOfYear(date) + length))) { return(true); } return(false); } int month = hd.GetMonth(value); // all false options: different months(not Adar in leep year) or an erlier day in the month - same length of month if (month < hd.GetMonth(date) && hd.IsLeapYear(hd.GetYear(date)) == false) { return(false); } //both are ether leap or not, The differencse is by the months if (Math.Abs(hd.GetDaysInYear(hd.GetYear(value)) - hd.GetDaysInYear(hd.GetYear(date))) <= 2) { return(CheckRange(hd.GetYear(date), month, hd.GetDayOfMonth(value), value, date, length)); } else if (hd.IsLeapYear(hd.GetYear(value)) == true) { if (month > 6) { month -= 1; } if (hd.GetMonth(value) != 6) { return(CheckRange(hd.GetYear(date), month, hd.GetDayOfMonth(value), value, date, length)); } else { return(false); } } //date is a leap year else { if (month >= 6) { month += 1; } if (hd.GetMonth(date) == 6 || (hd.GetMonth(date) < 6 && (hd.GetMonth(hd.AddDays(date, length)) >= 6))) { return(false); } return(CheckRange(hd.GetYear(date), month, hd.GetDayOfMonth(value), value, date, length)); } }
[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 bool CreateCalendar(string calendarName, out Calendar calendar) { calendar = null; bool result = false; if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Arabic")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.Arabic); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Middle East French")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.MiddleEastFrench); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated English")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedEnglish); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian Transliterated French")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.TransliteratedFrench); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian US English")) { result = true; calendar = new GregorianCalendar(GregorianCalendarTypes.USEnglish); } else if (Validator.CompareWithInvariantCulture(calendarName, "Hebrew")) { calendar = new HebrewCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Hijri")) { calendar = new HijriCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Japanese")) { calendar = new JapaneseCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Korea")) { calendar = new KoreanCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Taiwan")) { calendar = new TaiwanCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Thai Buddhist")) { calendar = new ThaiBuddhistCalendar(); } else if (Validator.CompareWithInvariantCulture(calendarName, "Gregorian")) { calendar = new GregorianCalendar(); } return(result); }
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(); } }
/// <summary> /// Gets the TorahPortion that is read on that week's Shabbos. If, however, a YomTov falls on the Shabbos, and the Parsha gets pushed off, it returns null. /// </summary> /// <param name="Year">That Jewish year</param> /// <param name="Week">The number of the week starting from Rosh Hashanah</param> /// <param name="inIsrael">A boolean value indicating the user's location, this has an effect on the Parsha</param> /// <returns>The Torah portion that is read that Shabbos</returns> public TorahPortion?GetTorahPortion(int Year, int Week, bool inIsrael) { HebrewCalendar hebCal = new HebrewCalendar(); JewishDate date = hebCal.AddWeeks(new JewishDate(Year, 1, 1), Week - 1); return(GetTorahPortion(date, inIsrael)); }
/// <summary> /// متد تبديل تاريخ ميلادي به هبري /// </summary> public void MiladiToHebrew() { HebrewCalendar hb = new HebrewCalendar(); DateTime dt = new DateTime(year: Year, month: Month, day: Day); string result = $"Miladi To Hebrew:{ hb.GetYear(dt).ToString("0000/") } { hb.GetMonth(dt).ToString("00/") } { hb.GetDayOfMonth(dt).ToString("00") }"; System.Console.Write(result); }
[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); }
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(); }
public MyPopupForm(HebrewCalendarEdit owner) : base(owner) { Calendar = new HebrewCalendar { Dock = DockStyle.Fill }; Calendar.KeyUp += Calendar_KeyUp; Calendar.DateClicked += Calendar_DateClicked; Controls.Add(Calendar); }
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)); } }
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)); } }
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); }
[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); }
public JewishDate(DateTime date) { var jewishCulture = CreateJewishCulture(); HebrewCalendar calendar = (HebrewCalendar)jewishCulture.DateTimeFormat.Calendar; // convert gregorian date to jewish date _month = calendar.GetMonth(date); _year = calendar.GetYear(date); _day = calendar.GetDayOfMonth(date); _monthLabel = GetHebrewMonth(_month, calendar.IsLeapYear(_year)); _isLeap = calendar.IsLeapYear(_year); }
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); } }
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); }
/// <summary> /// Sets the date according to the Gregorian Calendar /// </summary> /// <param name="date">The Gregorian date</param> public JewishDate(DateTime date) { GregDate = date; HebrewCalendar hebCal = new HebrewCalendar(); Year = hebCal.GetYear(date); Month = hebCal.GetMonth(date); Day = hebCal.GetDayOfMonth(date); DayOfWeek = hebCal.GetDayOfWeek(GregDate); DayOfYear = hebCal.GetDayOfYear(GregDate); }
/// <summary> /// Sets the date according to the Hebrew Calendar /// </summary> /// <param name="year">Number of years since Creation</param> /// <param name="month">Month of the year</param> /// <param name="day">Day of the month</param> public JewishDate(int year, int month, int day) { HebrewCalendar hebCal = new HebrewCalendar(); GregDate = hebCal.ToDateTime(year, month, day, 0, 0, 0, 0); Year = year; Month = month; Day = day; DayOfWeek = hebCal.GetDayOfWeek(GregDate); DayOfYear = hebCal.GetDayOfYear(GregDate); }
public static List <QueData> GetHeb(DateTime from, DateTime to) { Calendar HebCal = new HebrewCalendar(); int days = (to - from).Days; List <QueData> lst = new List <QueData>(); for (int i = 0; i <= days; i++) { int curMonth = HebCal.GetMonth(from); if (dicHolidays.ContainsKey(curMonth)) { int curDay = HebCal.GetDayOfMonth(from); string hol = dicHolidays[curMonth]; string currentDay = curDay.ToString(); if (hol.Contains("," + currentDay + ",")) { QueData qData = new QueData(); if (curMonth == 9 && from.DayOfWeek == DayOfWeek.Monday)//יום עצמאות ביום שני { qData = getQue(from.AddDays(1), dicHolidaysDesc[curMonth.ToString() + currentDay]); } else if (curMonth == 9 && from.DayOfWeek == DayOfWeek.Friday)//יום עצמאות ביום שישי { qData = getQue(from.AddDays(-1), dicHolidaysDesc[curMonth.ToString() + currentDay]); } else if (curMonth == 9 && from.DayOfWeek == DayOfWeek.Saturday)//יום עצמאות ביום שבת { qData = getQue(from.AddDays(-2), dicHolidaysDesc[curMonth.ToString() + currentDay]); } else { qData = getQue(from, dicHolidaysDesc[curMonth.ToString() + currentDay]); } lst.Add(qData); } } from = from.AddDays(1); } //int curYear = HebCal.GetYear(Today); //int curDay = HebCal.GetDayOfMonth(Today); //DateTime d = HebCal.ToDateTime(curYear, curMonth, curDay, 0, 0, 0, 0); return(lst); }
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"); }
public static void Main() { HebrewCalendar hc = new HebrewCalendar(); DateTime date1 = new DateTime(5771, 6, 1, hc); DateTime date2 = hc.ToDateTime(5771, 6, 1, 0, 0, 0, 0); Console.WriteLine("{0:d} (Gregorian) = {1:d2}/{2:d2}/{3:d4} ({4}): {5}", date1, hc.GetMonth(date2), hc.GetDayOfMonth(date2), hc.GetYear(date2), GetCalendarName(hc), date1.Equals(date2)); }
public HebrewDateResponse(DateTime date) { var hebrewCalendar = new HebrewCalendar(); var year = hebrewCalendar.GetYear(date); var month = hebrewCalendar.GetMonth(date); var day = hebrewCalendar.GetDayOfMonth(date); CultureInfo culture = CultureInfo.CreateSpecificCulture("he-IL"); culture.DateTimeFormat.Calendar = hebrewCalendar; Thread.CurrentThread.CurrentCulture = culture; HebrewDate = $"{year.ToString().PadLeft(4, '0')}-{month.ToString().PadLeft(2, '0')}-{day.ToString().PadLeft(2, '0')}"; WrittenDate = $"{day} {GetHebrewMonthDate(month, year, hebrewCalendar)} {year}"; }
public static void Main(string[] args) { //各種暦を作成 GregorianCalendar gre = new GregorianCalendar(); JapaneseCalendar jpn = new JapaneseCalendar(); JapaneseLunisolarCalendar jpnLun = new JapaneseLunisolarCalendar(); HebrewCalendar heb = new HebrewCalendar(); //各暦での現在の日付を表示 WriteCalendar(gre); WriteCalendar(jpn); WriteCalendar(jpnLun); WriteCalendar(heb); Console.ReadKey(); }
public static DateTime HebrewDateToGregorianDate(int year, int day, int?month = null, string monthLabel = null, bool?isLeap = null) { var jewishCulture = CreateJewishCulture(); HebrewCalendar calendar = (HebrewCalendar)jewishCulture.DateTimeFormat.Calendar; if (isLeap == null) { isLeap = calendar.IsLeapYear(year); } if (month == null) { month = GetHebrewMonthNumber(monthLabel, (bool)isLeap); } return(calendar.ToDateTime(year, month.Value, day, 0, 0, 0, 0)); }
private string GetHebrewMonthDate(int month, int year, HebrewCalendar hebrewCalendar) { switch (month) { case 1: return("Tishri"); case 2: return("Heshvan"); case 3: return("Kislev"); case 4: return("Tevet"); case 5: return("Shevat"); case 6: return("Adar" + (hebrewCalendar.IsLeapYear(year) ? " I" : string.Empty)); case 7: return(hebrewCalendar.IsLeapYear(year) ? "Adar II" : "Nissan"); case 8: return(hebrewCalendar.IsLeapYear(year) ? "Nissan" : "Iyar"); case 9: return(hebrewCalendar.IsLeapYear(year) ? "Iyar" : "Sivan"); case 10: return(hebrewCalendar.IsLeapYear(year) ? "Sivan" : "Tammouz"); case 11: return(hebrewCalendar.IsLeapYear(year) ? "Tammouz" : "Av"); case 12: return(hebrewCalendar.IsLeapYear(year) ? "Av" : "Eloul"); case 13: return("Eloul"); default: return(null); } }
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 MyPopupForm(HebrewCalendarEdit owner) : base(owner) { Calendar = new HebrewCalendar { Dock = DockStyle.Fill }; Calendar.KeyUp += Calendar_KeyUp; Calendar.DateClicked += Calendar_DateClicked; Controls.Add(Calendar); }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; try { DateTime dTest; HebrewCalendar hCal = new HebrewCalendar(); JulianCalendar jCal = new JulianCalendar(); HijriCalendar hiCal = new HijriCalendar (); GregorianCalendar gCal = new GregorianCalendar (); JapaneseCalendar jaCal = new JapaneseCalendar (); KoreanCalendar kCal = new KoreanCalendar (); ThaiBuddhistCalendar tCal = new ThaiBuddhistCalendar (); strLoc = "Loc_100vy"; iCountTestcases++; dTest = new DateTime(5360,04,14,hCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_100aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_100bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_100cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_100dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_100ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_100ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_100gg! DateTime object was not set correctly"); } strLoc = "Loc_101vy"; iCountTestcases++; dTest = new DateTime(1599,12,22,jCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_101aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_101bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_101cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_101dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_101ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_101ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_101gg! DateTime object was not set correctly"); } strLoc = "Loc_102vy"; iCountTestcases++; dTest = new DateTime(1008,06,15,hiCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_102aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_102bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_102cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_102dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_102ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_102ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_102gg! DateTime object was not set correctly"); } strLoc = "Loc_103vy"; iCountTestcases++; dTest = new DateTime(1600,1,1,gCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_103aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_103bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_103cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_103dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_103ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_103ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_103gg! DateTime object was not set correctly"); } strLoc = "Loc_104vy"; iCountTestcases++; dTest = new DateTime(1,1,8,jaCal); if (dTest.Year != 1989) { ++iCountErrors; printerr( "Error_104aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_104bb! DateTime object was not set correctly"); } if (dTest.Day != 8) { ++iCountErrors; printerr( "Error_104cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_104dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_104ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_104ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_104gg! DateTime object was not set correctly"); } strLoc = "Loc_105vy"; iCountTestcases++; dTest = new DateTime(3933,1,1,kCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_105aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_105bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_105cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_105dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_105ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_105ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_105gg! DateTime object was not set correctly"); } strLoc = "Loc_106vy"; iCountTestcases++; dTest = new DateTime(2143,1,1,tCal); if (dTest.Year != 1600) { ++iCountErrors; printerr( "Error_106aa! DateTime object was not set correctly"); } if (dTest.Month != 1) { ++iCountErrors; printerr( "Error_106bb! DateTime object was not set correctly"); } if (dTest.Day != 1) { ++iCountErrors; printerr( "Error_106cc! DateTime object was not set correctly"); } if (dTest.Hour != 0) { ++iCountErrors; printerr( "Error_106dd! DateTime object was not set correctly"); } if (dTest.Minute != 0) { ++iCountErrors; printerr( "Error_106ee! DateTime object was not set correctly"); } if (dTest.Second != 0) { ++iCountErrors; printerr( "Error_106ff! DateTime object was not set correctly"); } if (dTest.Millisecond != 0) { ++iCountErrors; printerr( "Error_106gg! DateTime object was not set correctly"); } strLoc = "Loc_524vy"; iCountTestcases++; try { dTest = new DateTime(0,03,25,hCal); iCountErrors++; printerr( "Error_200bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_512ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_200aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_333vy"; iCountTestcases++; try { dTest = new DateTime(10000,03,25,hCal); iCountErrors++; printerr( "Error_300bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_333ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_300aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_444vy"; iCountTestcases++; try { dTest = new DateTime(5000,0,25,hCal); iCountErrors++; printerr( "Error_400bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_444ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_400aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_555vy"; iCountTestcases++; try { dTest = new DateTime(5000,13,25,jCal); iCountErrors++; printerr( "Error_500bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_555ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_500aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_665vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,0,jCal); iCountErrors++; printerr( "Error_600bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_665ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_600aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_777vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,32,jCal); iCountErrors++; printerr( "Error_700bb! No exception thrown"); } catch (ArgumentOutOfRangeException argexc) { printinfo( "Info_775ad! Caught ArguementOutOfRangeException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_700aa! Wrong exception thrown: " + e.ToString()); } strLoc = "Loc_888vy"; iCountTestcases++; try { dTest = new DateTime(2000,03,14,null); iCountErrors++; printerr( "Error_800bb! No exception thrown"); } catch (ArgumentNullException argexc) { printinfo( "Info_885ad! Caught ArguementNullException"); } catch (Exception e) { ++iCountErrors; printerr( "Error_800aa! Wrong exception thrown: " + e.ToString()); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }
// Set up for the tests. protected override void Setup() { calendar = new HebrewCalendar(); twoDigitYearMax = 5790; }
public static void HebrewTest() { HebrewCalendar cal = new HebrewCalendar(); Assert.False(cal.IsLeapMonth(5343, 4)); }
public bool runTest() { Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer); String strLoc = "Loc_000oo"; String strValue = String.Empty; int iCountErrors = 0; int iCountTestcases = 0; CultureInfo culture; DateTime date; Calendar calendar; String result; String expected; BitArray bits; Hashtable table; DictionaryEntry entry; Int32 startYear; try { calendar = new HebrewCalendar(); culture = new CultureInfo("he-IL"); culture.DateTimeFormat.Calendar = calendar; strLoc = "Loc_0273tsdg"; iCountTestcases++; date = new DateTime(2001, 10, 2); result = date.ToString(culture); expected = "\x05d8\x0022\x05d5"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_834sG! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result)); } date = new DateTime(2001, 10, 3); result = date.ToString(culture); expected = "\x05d8\x0022\x05d6"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_3947sg! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result)); } date = new DateTime(5370, 2, 15, calendar); result = date.ToString(culture); expected = "\x05d8\x0022\x05d5"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_3947tsg! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result)); } date = new DateTime(5370, 2, 16, calendar); result = date.ToString(culture); expected = "\x05d8\x0022\x05d6"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_3095g! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result)); } strLoc = "Loc_9347tsg"; iCountTestcases++; bits = new BitArray(new Boolean[]{true, false, false, true, false, false, true, false, true, false, false, true, false, false, true, false, false, true, false}); startYear = 5757; for(int i=startYear; i<(startYear+19);i++){ date = new DateTime(i, 7, 1, calendar); result = date.ToString("M", culture); if(bits[i-startYear]) expected = "\x05d0\x05d3\x05e8 \x05d1"; else expected = "\x05e0\x05d9\x05e1\x05df"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_027sdg_{2}! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result), (i-startYear)); } } strLoc = "Loc_9347tsg"; iCountTestcases++; startYear = 5761; table = new Hashtable(); table.Add(startYear, new DictionaryEntry(29, 29)); table.Add(startYear+1, new DictionaryEntry(29, 30)); table.Add(startYear+2, new DictionaryEntry(30, 30)); table.Add(startYear+3, new DictionaryEntry(30, 30)); table.Add(startYear+4, new DictionaryEntry(29, 29)); table.Add(startYear+5, new DictionaryEntry(29, 30)); table.Add(startYear+6, new DictionaryEntry(30, 30)); table.Add(startYear+7, new DictionaryEntry(29, 29)); table.Add(startYear+8, new DictionaryEntry(29, 30)); table.Add(startYear+9, new DictionaryEntry(30, 30)); for(int i=startYear; i<(startYear+10);i++){ date = new DateTime(i, 3, 1, calendar); date = date.Subtract(new TimeSpan(TimeSpan.TicksPerDay)); result = date.ToString(culture); entry = (DictionaryEntry)table[i]; if((Int32)entry.Key==29) expected = "\x05db\x0022\x05d8"; else expected = "\x05dc"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_347dgdzg_{2}! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result), (i-startYear)); } date = new DateTime(i, 4, 1, calendar); date = date.Subtract(new TimeSpan(TimeSpan.TicksPerDay)); result = date.ToString(culture); entry = (DictionaryEntry)table[i]; if((Int32)entry.Value==29) expected = "\x05db\x0022\x05d8"; else expected = "\x05dc"; if(result.IndexOf(expected)<0){ iCountErrors++; Console.WriteLine("Err_32408sdg_{2}! Unexpected result: Expected to contain: <{0}>, Returned: <{1}>", GetUnicodeString(expected), GetUnicodeString(result), (i-startYear)); } } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general=="+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFName+" ,inCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }