public NepaliDate AddMonths(int months) { DateTime dt = DateConvertor.GetEnglishDate(this.ToString()); dt = dt.AddMonths(months); return(DateConvertor.GetNepaliDate(dt)); }
public NepaliDate AddYears(int years) { DateTime dt = DateConvertor.GetEnglishDate(this.ToString()); dt = dt.AddYears(years); return(DateConvertor.GetNepaliDate(dt)); }
public int CompareTo(NepaliDate other) { DateTime engOther = DateConvertor.GetEnglishDate(other.ToString()); DateTime engThis = DateConvertor.GetEnglishDate(this.ToString()); return(engThis.CompareTo(engOther)); }
private bool ConvertStringToNepaliDate(string nepaliDate, DateFormatTypes dateFormatType) { int tmp = 0; switch (dateFormatType) { case DateFormatTypes.yyyyMMdd: //convert the date in YYYY/MM/DD format eg. 2065/03/05 to day, month and year. if (nepaliDate.Trim().Length == 10) { tmp = Conversion.ToInt32(nepaliDate.Substring(0, 4)); //extract year. if (DateConvertor.IsValidYear(tmp, true)) { _year = tmp; } else { throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05"); } //extract month: tmp = Conversion.ToInt32(nepaliDate.Substring(5, 2)); if (DateConvertor.GetDaysInNepaliMoth(_year, tmp) > 0) { _month = tmp; } else { throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05"); } //extract day: tmp = Conversion.ToInt32(nepaliDate.Substring(8, 2)); if (tmp > 0 && tmp <= DateConvertor.GetDaysInNepaliMoth(_year, _month)) { _day = tmp; } else { _day = DateConvertor.GetDaysInNepaliMoth(_year, _month); //current month days... if not exis } //throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05"); return(true); } else { throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05"); } //break; default: throw new Exception("Other date formats not supported"); } //return false; }
private void calc() { DaysInMonth = DateConvertor.GetDaysInNepaliMoth(Year, Month); NepaliDate np = new NepaliDate(Year, Month, 1); StartDate = DateConvertor.GetEnglishDate(np.ToString()); np.Day = DaysInMonth; EndDate = DateConvertor.GetEnglishDate(np.ToString()); }
/// <summary> /// Check if the given date is nepali date or not and returns to if a valid date. /// </summary> /// <param name="nepaliDate"></param> /// <param name="dateFormatType"></param> /// <returns>Returns true if valid date else false.</returns> public static bool IsValidDate(string nepaliDate, DateFormatTypes dateFormatType) { int tmp = 0; switch (dateFormatType) { case DateFormatTypes.yyyyMMdd: //convert the date in YYYY/MM/DD format eg. 2065/03/05 to day, month and year. if (nepaliDate.Trim().Length == 10) { tmp = Conversion.ToInt32(nepaliDate.Substring(0, 4)); int yr, mnth, days; //extract year. if (DateConvertor.IsValidYear(tmp, true)) { yr = tmp; } else { return(false); } //extract month: tmp = Conversion.ToInt32(nepaliDate.Substring(5, 2)); if (DateConvertor.GetDaysInNepaliMoth(yr, tmp) > 0) { mnth = tmp; } else { return(false); } //extract day: tmp = Conversion.ToInt32(nepaliDate.Substring(8, 2)); if (tmp > 0 && tmp <= DateConvertor.GetDaysInNepaliMoth(yr, mnth)) { days = tmp; } else { return(false); } return(true); } //throw new Exception("Date format must be YYYY/MM/DD. eg. 2065/03/05"); break; default: throw new Exception("Other date formats not supported"); } return(false); }