/// <summary> /// Converts the string representation of a Persian Date, to a <see cref="PersianCalendarEx"/> Instance. A return /// value indicates whether the operation succeeded. The string can contain a literal date description in Persian language. /// </summary> /// <param name="str">The string to convert.</param> /// <returns></returns> protected static PersianCalendarEx TryParseLiteralDate(string str) { PersianDateParser pd = new PersianDateParser(); PersianDatePatternInfo[] pis = pd.FindAndParse(str); DateTime dt; foreach (PersianDatePatternInfo pi in pis) { if (pi.CalendarType != DateCalendarType.Jalali && pi.CalendarType != DateCalendarType.Illegal) { continue; } if (pi.YearNumber >= 0 && pi.DayNumber > 0 && pi.MonthNumber > 0) { try { dt = new DateTime(pi.YearNumber, pi.MonthNumber, pi.DayNumber, new PersianCalendar()); return(new PersianCalendarEx(dt)); } catch { continue; } } } return(null); }
/// <summary> /// Converts the string representation of a Hijri Ghamari Date, to a <see cref="HijriCalendarEx"/> Instance. A return /// value indicates whether the operation succeeded. The string can contain a literal date description in Persian language. /// </summary> /// <param name="str">The string to convert.</param> /// <returns></returns> protected static HijriCalendarEx TryParseLiteralDate(string str) { PersianDateParser pd = new PersianDateParser(); PersianDatePatternInfo[] pis = pd.FindAndParse(str); foreach (PersianDatePatternInfo pi in pis) { if (pi.CalendarType != DateCalendarType.HijriGhamari && pi.CalendarType != DateCalendarType.Illegal) { continue; } if (pi.YearNumber >= 0 && pi.DayNumber > 0 && pi.MonthNumber > 0) { try { return(new HijriCalendarEx(pi.YearNumber, pi.MonthNumber, pi.DayNumber)); } catch { continue; } } } return(null); }