public static int MinutesIff(PersianDateTime date1, PersianDateTime date2) { int defday = DayIff(date1, date2); if (defday == 0)// hatman dar yek roz hastand { TimeSpan start = new TimeSpan(date1.Hour, date1.Minute, date1.Secend); TimeSpan end = new TimeSpan(date2.Hour, date2.Minute, date2.Secend); return(defday * 1440 + Convert.ToInt32((end.TotalMinutes - start.TotalMinutes))); } else if (defday > 0)//roze dovom bozorgtar az roze aval ast { TimeSpan start = new TimeSpan(date1.Hour, date1.Minute, date1.Secend); TimeSpan end = new TimeSpan(date2.Hour, date2.Minute, date2.Secend); return(defday * 1440 + Convert.ToInt32((end.TotalMinutes - start.TotalMinutes))); } else if (defday < 0)// roze aval bozorgtar az roze dovom ast { TimeSpan end = new TimeSpan(date1.Hour, date1.Minute, date1.Secend); TimeSpan start = new TimeSpan(date2.Hour, date2.Minute, date2.Secend); return(defday * 1440 + Convert.ToInt32((end.TotalMinutes - start.TotalMinutes))); } //defminutes=((date2.Hour-date2.Hour))*60+(date2.Minute) return(0); }
public static string TostringForGrid(PersianDateTime date, PersianDateType format) { if (date == null) { return("---"); } return(date.ToString(format)); }
/// <summary> /// mohasebe tedad roz haye beyne 2 roz, if date1>date2 then retunr negetiv number else posetive number /// </summary> /// <param name="date1"></param> /// <param name="date2"></param> /// <returns></returns> public static int DayIff(PersianDateTime date1, PersianDateTime date2) { PersianDateTime temp; int zarib = 1; int miladicompaire = DateTime.Compare(date1.Datetime, date2.Datetime); if (miladicompaire == 0) { return(0); } if (miladicompaire > 0) { temp = date1; date1 = date2; date2 = temp; zarib = -1; } int deffday = 0; int deffyear; if (date2.Year == date1.Year)// dar yek sal hastand { return(date2.Dayofyear - date1.Dayofyear); } else // dar yek sal nistand { deffyear = date1.Year; if (IsLeap(date1.Year)) { deffday = 366 - date1.Dayofyear; } else { deffday = 365 - date1.Dayofyear; } deffyear++; while (deffyear < date2.Year) { if (IsLeap(deffyear)) { deffday = deffday + 366; } else { deffday = deffday + 365; } deffyear++; } return((deffday + date2.Dayofyear) * zarib); } }
/// <summary> /// gereftane tarikh akharin roze mah /// </summary> /// <param name="currentmonthdate">yek roz az un mahi ke akharin rozash ra mikhaheed</param> /// <returns>tarikh akharin roz un mah</returns> public static PersianDateTime GetLastDayOfMonth(PersianDateTime currentmonthdate) { PersianDateTime result = new PersianDateTime(currentmonthdate.Year, currentmonthdate.Month, currentmonthdate.Day); int lastday = currentmonthdate.Day; int year = currentmonthdate.Year; while (true) { result.AddDays(1); if (result.Month != currentmonthdate.Month) { break; } lastday++; } result.AddDays(-1); return(result); }
/// <summary> /// aya sale kabise ast ya kheyr /// </summary> /// <param name="year"></param> /// <returns></returns> public static bool IsLeap(int year) { PersianDateTime x = new PersianDateTime(year, 12, 27); int lastdaye = 27; while (true) { x.AddDays(1); lastdaye++; if (x.Month != 12) { break; } } if (lastdaye - 1 == 30) { return(true); } return(false); }
/// <summary> /// kam kardan ye TimeSpanBatis be in date /// </summary> /// <param name="value"></param> /// <returns></returns> public PersianDateTime Subtract(PersianDateTime date, TimeSpan value) { return(new PersianDateTime(date.Datetime.Subtract(value))); }
/// <summary> /// ezafe kardan ye TimeSpanBatis be in date /// </summary> /// <param name="value"></param> /// <returns></returns> public static PersianDateTime Add(PersianDateTime date, TimeSpan value) { return(new PersianDateTime(date.Datetime.Add(value))); }