/// <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);
        }
Example #2
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);
        }