/// <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); }
protected override StringVerificationData FindPattern(string content) { m_lstPatternInfo.Clear(); foreach (var pi in m_perianDataParser.FindAndParse(content)) { if (pi.YearNumber >= 0) { m_lstPatternInfo.Add(pi); } } foreach (var pi in m_englishDateParser.FindAndParse(content)) { if (pi.YearNumber >= 0) { m_lstPatternInfo.Add(pi); } } foreach (var pi in m_numericDateParser.FindAndParse(content)) { m_lstPatternInfo.Add(pi); } if (m_lstPatternInfo.Count <= 0) { return(null); } m_minPi = PeakFirstVerification(); return(new StringVerificationData { ErrorIndex = m_minPi.Index, ErrorLength = m_minPi.Length, ErrorType = VerificationTypes.Information, Suggestions = new DateSuggestion { Message = "موارد یافت شده:", MainPattern = m_minPi } }); }