//
        /// <summary>
        /// اختلاف بین دو تاریخ شمسی را به تعداد روز محاسبه میکند
        /// </summary>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <returns>اختلاف به تعداد روز</returns>
        internal static int GetDateDifference(string fromDate, string toDate)
        {
            var fromYearMonthDay = YearMonthDayManager.GetYearMonthDay(fromDate);
            var toYearMonthDay   = YearMonthDayManager.GetYearMonthDay(toDate);
            var fromMiladidate   = GetDateTime(fromYearMonthDay);
            var toMiladiDate     = GetDateTime(toYearMonthDay);
            int dateDifference   = (int)(toMiladiDate - fromMiladidate).TotalDays;

            return(dateDifference);
        }
        //
        internal static int GetPartialDateCount(string fromOverallDate, string toOverallDate, string fromPartialDate,
                                                string toPartialDate)
        {
            string    date1, date2;
            const int ZERO = 0;

            var fromOverallMiladi = GetDateTime(YearMonthDayManager.GetYearMonthDay(fromOverallDate));
            var toOverallMiladi   = GetDateTime(YearMonthDayManager.GetYearMonthDay(toOverallDate));
            var fromPartialMiladi = GetDateTime(YearMonthDayManager.GetYearMonthDay(fromPartialDate));
            var toPartialMiladi   = GetDateTime(YearMonthDayManager.GetYearMonthDay(toPartialDate));

            ValidateDates(fromOverallMiladi, toOverallMiladi);
            ValidateDates(fromPartialMiladi, toPartialMiladi);
            //
            // <--------------->p
            //          <--------------------------->o
            if (fromPartialMiladi <= fromOverallMiladi && toPartialMiladi <= toOverallMiladi && fromOverallMiladi <= toPartialMiladi)
            {
                date1 = fromOverallDate;
                date2 = toPartialDate;
            }
            //
            //  <----------->p
            //<---------------->o
            else if (fromOverallMiladi <= fromPartialMiladi && toPartialMiladi <= toOverallMiladi && fromOverallMiladi <= toPartialMiladi)
            {
                date1 = fromPartialDate;
                date2 = toPartialDate;
            }
            //
            //             <------>p
            // <-------------->o
            else if (fromOverallMiladi <= fromPartialMiladi && toOverallMiladi <= toPartialMiladi && fromPartialMiladi <= toOverallMiladi)
            {
                date1 = fromPartialDate;
                date2 = toOverallDate;
            }
            //
            // <----------------------------->p
            //    <------------------->o
            else if (fromPartialMiladi <= fromOverallMiladi && toOverallMiladi <= toPartialMiladi && fromOverallMiladi <= toPartialMiladi)
            {
                date1 = fromOverallDate;
                date2 = toOverallDate;
            }
            else
            {
                return(ZERO);
            }
            return(GetDateDifference(date1, date2));
        }
        internal static string GetJalaliDate(DateTime dateTime, PersianDateType persianDateType)
        {
            var yearMonthDay = YearMonthDayManager.GetYearMonthDay(dateTime);

            switch (persianDateType)
            {
            case PersianDateType.EightCharWithoutSlash:
                return(GetJalaliDateEightCharWithoutSlash(yearMonthDay));

            case PersianDateType.EightCharWithSlash:
                return(GetJalaliDateEightCharWithSlash(yearMonthDay));

            case PersianDateType.SixChar:
                return(GetJalaliDateSixChar(yearMonthDay));

            case PersianDateType.TenChar:
                return(GetJalaliDateTenChar(yearMonthDay));

            default:
                throw new NotImplementedException();
            }
        }
Exemple #4
0
 public static YearMonthDay GetYearMonthDay(string persianDate)
 {
     return(YearMonthDayManager.GetYearMonthDay(persianDate));
 }