public static bool IsValid(long value)
        {
            string          stringValue = string.Format("{0:0000'/'00'/'00','00':'00':'00}", value);
            PersianDateTime persianDateTime;

            return(PersianDateTime.TryParse(stringValue, out persianDateTime));
        }
        public static PersianDateTime Parse(string value)
        {
            PersianDateTime dt = new PersianDateTime();

            if (TryParse(value, out dt))
            {
                return(dt);
            }
            return(new PersianDateTime());
        }
        public string ToRelativeString(PersianDateTime baseDate = null, string baseFormat = "s", TimeSpan?exclusiveRelativeTimeSpan = null)
        {
            PersianDateRange persianDateRange = new PersianDateRange(this, baseDate ?? PersianDateTime.Now);
            TimeSpan         passedTimeSpan   = persianDateRange.TimeSpan;

            if (exclusiveRelativeTimeSpan == null)
            {
                exclusiveRelativeTimeSpan = new TimeSpan(7, 0, 0, 0);
            }
            if (passedTimeSpan >= exclusiveRelativeTimeSpan)
            {
                return(this.ToString(baseFormat));
            }


            if ((int)passedTimeSpan.TotalMinutes == 0)
            {
                return("چند ثانیه قبل");
            }
            else if (passedTimeSpan.TotalMinutes < 60)
            {
                return(string.Format("{0} دقیقه قبل", passedTimeSpan.Minutes.LocalizeNumbers()));
            }
            else if (passedTimeSpan.TotalHours < 24)
            {
                return(string.Format("{0} ساعت قبل", passedTimeSpan.Hours.LocalizeNumbers()));
            }
            else if (passedTimeSpan.TotalDays == 1)
            {
                return(string.Format("دیروز", passedTimeSpan.Days.LocalizeNumbers()));
            }
            else if (passedTimeSpan.TotalDays < 7)
            {
                return(string.Format("{0} روز قبل", passedTimeSpan.Days.LocalizeNumbers()));
            }
            return(this.ToString(baseFormat));
        }
 public PersianDateTime Add(TimeSpan offsetValue)
 {
     return(PersianDateTime.FromGorgian(DateTime.AddTicks(offsetValue.Ticks)));
 }
        public static bool TryParse(string value, out PersianDateTime date)
        {
            date = new PersianDateTime();

            string datePart    = value;
            string timePart    = string.Empty;
            bool   hasTimePart = value.Contains(',');

            if (hasTimePart)
            {
                var parts = value.Split(',');
                datePart = parts[0];
                timePart = parts[1];
            }

            //Match m = Regex.Match(datePart, @"(?<year>\d{2,4})/(?<month>\d{1,2})/(?<day>\d{1,2})");
            Match m = ParsingRegex.Match(datePart);

            if (!m.Success)
            {
                return(false);
            }
            string yearText  = m.Result("${year}");
            string monthText = m.Result("${month}");
            string dayText   = m.Result("${day}");

            int year, month, day;

            if (!(int.TryParse(yearText, out year) && int.TryParse(monthText, out month) && int.TryParse(dayText, out day)))
            {
                return(false);
            }
            if (year < 100)
            {
                year += 1300;
            }
            if (year < 1300 || year > 1400)
            {
                return(false);
            }

            int hour = 0, minute = 0, second = 0;

            if (hasTimePart)
            {
                Match timeMatch = Regex.Match(timePart, @"(?<hour>\d{1,2}):(?<min>\d{1,2}):(?<sec>\d{1,2})");
                if (timeMatch.Success)
                {
                    string hourText = timeMatch.Result("${hour}");
                    string minText  = timeMatch.Result("${min}");
                    string secText  = timeMatch.Result("${sec}");
                    if (!int.TryParse(hourText, out hour) || !int.TryParse(minText, out minute) || !int.TryParse(secText, out second))
                    {
                        return(false);
                    }

                    if (hour < 0 || hour > 24)
                    {
                        return(false);
                    }
                    if (minute < 0 || minute > 59)
                    {
                        return(false);
                    }
                    if (second < 0 || second > 59)
                    {
                        return(false);
                    }
                }
            }
            try
            {
                date = new PersianDateTime(year, month, day, hour, minute, second);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
 public PersianDateTime AddSeconds(int seconds)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddSeconds(DateTime, seconds)));
 }
 public PersianDateTime AddMinutes(int minutes)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddMinutes(DateTime, minutes)));
 }
 public PersianDateTime AddHours(int hours)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddHours(DateTime, hours)));
 }
 public PersianDateTime AddDays(int days)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddDays(DateTime, days)));
 }
 public PersianDateTime AddMonths(int monthes)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddMonths(DateTime, monthes)));
 }
 public PersianDateTime AddYears(int years)
 {
     return(PersianDateTime.FromGorgian(Calendar.AddYears(DateTime, years)));
 }