/// <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 numberical representation of a date.
        /// </summary>
        /// <param name="str">The string to convert.</param>
        /// <returns></returns>
        protected static PersianCalendarEx TryParseNumericDate(string str)
        {
            NumericDateParser numericDateParser = new NumericDateParser();

            NumericDatePatternInfo[] patternInfos = numericDateParser.FindAndParse(str);

            DateTime dt;

            foreach (NumericDatePatternInfo pi in patternInfos)
            {
                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);
        }
示例#2
0
        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
                }
            });
        }
示例#3
0
        /// <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 numberical representation of a date.
        /// </summary>
        /// <param name="str">The string to convert.</param>
        /// <returns></returns>
        protected static HijriCalendarEx TryParseNumericDate(string str)
        {
            NumericDateParser pd = new NumericDateParser();

            NumericDatePatternInfo[] pis = pd.FindAndParse(str);

            foreach (NumericDatePatternInfo pi in pis)
            {
                if (pi.YearNumber >= 0 && pi.DayNumber > 0 && pi.MonthNumber > 0)
                {
                    try
                    {
                        return(new HijriCalendarEx(pi.YearNumber, pi.MonthNumber, pi.DayNumber));
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            return(null);
        }