/// <summary> /// /// </summary> /// <param name="TheDate">TheDate is normal Gregorian date</param> /// <param name="year"></param> /// <param name="month"></param> /// <param name="day"></param> /// <returns></returns> public static DateTime AddYearMonthDayInUmAlQuraDate(DateTime TheDate, int year, int month, int day) { DateTime date1 = new DateTime(TheDate.Year, TheDate.Month, TheDate.Day, new GregorianCalendar()); UmAlQuraCalendar cal = new UmAlQuraCalendar(); date1 = cal.AddYears(date1, year); date1 = cal.AddMonths(date1, month); date1 = cal.AddDays(date1, day); return(date1); }
/// <summary> /// Add Years or Months or days /// </summary> /// <param name="Date">yyyy/MM/dd</param> /// <param name="Part">Y=Year, M=Month, D=Day</param> /// <param name="Val">Give it Value</param> /// <param name="format">Give it format</param> /// <returns></returns> public static string Hij_AddPart(string Date, string Part, int Val, string format) { int Year = Convert.ToInt32(Date.Substring(0, 4)); int Month = Convert.ToInt32(Date.Substring(5, 2)); int day = Convert.ToInt32(Date.Substring(8, 2)); CultureInfo arCul = new CultureInfo("ar-SA"); UmAlQuraCalendar h = new UmAlQuraCalendar(); arCul.DateTimeFormat.Calendar = h; DateTime dat = new DateTime(); if (Part == "Y") { dat = h.AddYears(new DateTime(Year, Month, day, h), Val); } else if (Part == "D") { dat = h.AddDays(new DateTime(Year, Month, day, h), Val); } return(dat.ToString(format, arCul.DateTimeFormat)); }
public UmAlQuraDateTime AddDays(int days) { return(new UmAlQuraDateTime(s_calendar.AddDays(this.DateTime, days))); }
/// <summary> /// int[0] is Years /// int[1] is Months /// int[2] is days /// int[3] is Hours /// int[4] is Minutes /// int[5] is Seconds /// int[6] is Milliseconds /// </summary> /// <param name="StartDate">dd/MM/yyyy</param> /// <param name="EndDate">dd/MM/yyyy</param> /// <param name="format">D means in days onty , YMD means years ,months days .....</param> /// <returns></returns> public static int[] Get_HijriDiff_Y_M_D(string StartDate, string EndDate, string format) { short StartDateYear = Convert.ToInt16(StartDate.Substring(0, 4)); short StartDateMonth = Convert.ToInt16(StartDate.Substring(5, 2)); short StartDateday = Convert.ToInt16(StartDate.Substring(8, 2)); short EndDateYear = Convert.ToInt16(EndDate.Substring(0, 4)); short EndDateMonth = Convert.ToInt16(EndDate.Substring(5, 2)); short EndDateday = Convert.ToInt16(EndDate.Substring(8, 2)); CultureInfo arCul = new CultureInfo("ar-SA"); UmAlQuraCalendar h = new UmAlQuraCalendar(); arCul.DateTimeFormat.Calendar = h; DateTime StartDatedat = new DateTime(StartDateYear, StartDateMonth, StartDateday, h); DateTime EndDatedat = new DateTime(EndDateYear, EndDateMonth, EndDateday, h); int adys = 0; int amns = 0; int ayrs = 0; if (format == "YMD") { bool itsmns = false; bool itdys = false; while (StartDatedat < EndDatedat) { if (!itsmns) { StartDatedat = h.AddYears(StartDatedat, 1); if (StartDatedat > EndDatedat) // اقل من سنة { StartDatedat = h.AddYears(StartDatedat, -1); itsmns = true; } else { ayrs++; } } else { if (!itdys) { StartDatedat = h.AddMonths(StartDatedat, 1); if (StartDatedat > EndDatedat) // اقل من شهر { StartDatedat = h.AddMonths(StartDatedat, -1); itdys = true; } else { amns++; } } else { StartDatedat = h.AddDays(StartDatedat, 1); if (StartDatedat > EndDatedat) // اقل من يوم { StartDatedat = h.AddDays(StartDatedat, -1); } else { adys++; } } } } } else { adys = Convert.ToInt32((EndDatedat - StartDatedat).TotalDays + 1); } TimeSpan difference = EndDatedat.Subtract(StartDatedat); int[] Resut = new int[7]; Resut[0] = ayrs; Resut[1] = amns; Resut[2] = adys; Resut[3] = difference.Hours; Resut[4] = difference.Minutes; Resut[5] = difference.Seconds; Resut[6] = difference.Milliseconds; //"الفرق : " + //ayrs.ToString() + " سنة" + //", " + amns.ToString() + " شهر" + //", " + adys.ToString() + " يوم" + //", " + difference.Hours.ToString() + " ساعة" + //", " + difference.Minutes.ToString() + " دقيقة" + //", " + difference.Seconds.ToString() + " ثانية" + //", " + difference.Milliseconds.ToString() + " جزء من الثانية"; return(Resut); }
/// <summary> /// Add UmAlqura days to a given Datetime /// </summary> /// <param name="date">a given date to add UmAlqura days</param> /// <param name="years">Numbers of days to be added</param> /// <returns>Datetime after days added</returns> public static DateTime AddHijriDays(this DateTime date, int days) { UmAlQuraCalendar calendar = new UmAlQuraCalendar(); return(calendar.AddDays(date, days)); }