public static DateTime GetWeeksLater(this DateTime dt, int numberOfWeeksLater = 1, Culture cul = null)
 {
     return(GetDaysLater(dt, numberOfWeeksLater * 7, cul));
 }
        public static DateTime GetYearsLater(this DateTime dt, int numberOfYearsLater = 1, Culture cul = null)
        {
            if (cul == null)
            {
                cul = Globals.CurrentCulture;
            }
            int year, month, day;

            ConvertToCalendar(dt, out year, out month, out day, cul.Calendar);
            year = year + numberOfYearsLater;
            AdjustDateTimeOverFlow(ref day, ref month, ref year, cul);
            DateTime enddate = ConvertFromCalendar(year, month, day);

            return(enddate);
        }
 public static string GetTimeString(this DateTime?dt, Culture cul = null, CalendarTypes?cal = null)
 {
     return(GetDateTimeStr("", dt, cul, cal));
 }
        internal static bool GetDefaultCalendarDateFromString(this string input,
                                                              out int year,
                                                              out int month,
                                                              out int day,
                                                              char separator                = (char)0,
                                                              Culture inputculture          = null,
                                                              DateTimeParseOrder parseOrder = DateTimeParseOrder.DMY)
        {
            if (inputculture == null)
            {
                inputculture = Globals.CurrentCulture;
            }
            if (separator == (char)0)
            {
                separator = Globals.CurrentCulture.DateSeparator[0];
            }
            if (inputculture.Equals(SupportedCultures.FaIr))
            {
                PersianCalendar.DateFormatType df;
                switch (parseOrder)
                {
                case DateTimeParseOrder.YMD:
                    df = PersianCalendar.DateFormatType.YMD;
                    break;

                case DateTimeParseOrder.YDM:
                    df = PersianCalendar.DateFormatType.YDM;
                    break;

                case DateTimeParseOrder.DMY:
                    df = PersianCalendar.DateFormatType.DMY;
                    break;

                case DateTimeParseOrder.DYM:
                    df = PersianCalendar.DateFormatType.DYM;
                    break;

                case DateTimeParseOrder.MYD:
                    df = PersianCalendar.DateFormatType.MYD;
                    break;

                case DateTimeParseOrder.MDY:
                    df = PersianCalendar.DateFormatType.MDY;
                    break;

                default:
                    df = PersianCalendar.DateFormatType.UnknownFormat;
                    break;
                }
                if (input.Contains(":") && input.Contains(" "))
                {
                    var inputs = input.Split(' ');
                    if (inputs.Length == 2)
                    {
                        if (inputs[0].Contains(":") ^ inputs[1].Contains(":"))
                        {
                            if (inputs[0].Contains(":"))
                            {
                                input = inputs[1];
                            }
                            else
                            {
                                input = inputs[0];
                            }
                        }
                    }
                }
                var pdt = PersianCalendar.PersianDateTime.ParseDate(input, separator, ref df);
                year  = pdt.Year;
                month = pdt.Month;
                day   = pdt.Day;
                return(true);
            }
            if (inputculture.Equals(SupportedCultures.EnUs))
            {
                var dt = DateTime.Parse(input);
                year  = dt.Year;
                month = dt.Month;
                day   = dt.Day;
                return(true);
            }
            year = month = day = 0;
            return(false);
        }
 internal static void AdjustDateTimeOverFlow(ref int day, ref int month, ref int year, Culture cul = null)
 {
     if (cul == null)
     {
         cul = Globals.CurrentCulture;
     }
     while (month > GetMonthsInYear(year, cul) || day > GetDaysInMonth(month, year, cul))
     {
         while (month > GetMonthsInYear(year, cul))
         {
             month = month - GetMonthsInYear(year, cul);
             year++;
         }
         while (day > GetDaysInMonth(month, year, cul))
         {
             day = day - GetDaysInMonth(month, year, cul);
             month++;
         }
     }
 }
 public static string GetDateTimeString(this DateTime dt, string format = "", Culture cul = null, CalendarTypes?cal = null)
 {
     return(GetDateTimeString(format, dt, cul, cal));
 }
 public static string GetDateTimeString(this DateTime dt, Culture cul, CalendarTypes?cal = null)
 {
     return(GetDateTimeString(dt as DateTime?, cul, cal));
 }