public JalaliCalendar GetPersianDateTime(DateTime helper, string format = "yyyy/mm/dd")
        {
            var pc = MyPersianCalendar();

            if (helper.Year < 1000)
            {
                helper = DateTime.Now;
            }
            var persianCalendarPart = new JalaliCalendar();

            persianCalendarPart.Year           = pc.GetYear(helper);
            persianCalendarPart.Month          = pc.GetMonth(helper);
            persianCalendarPart.Day            = pc.GetDayOfMonth(helper);
            persianCalendarPart.DayOfYear      = pc.GetDayOfYear(helper);
            persianCalendarPart.DaysInYears    = GetDayInYears(persianCalendarPart);
            persianCalendarPart.MonthsInYears  = GetMonthsInYears(persianCalendarPart);
            persianCalendarPart.MonthTotalDays = pc.GetDaysInMonth(persianCalendarPart.Year, persianCalendarPart.Month);

            persianCalendarPart.Hour         = pc.GetHour(helper);
            persianCalendarPart.Minute       = pc.GetMinute(helper);
            persianCalendarPart.MinuteOfYear = (persianCalendarPart.DayOfYear * 24 * 60) + (persianCalendarPart.Hour * 60) + persianCalendarPart.Minute;
            persianCalendarPart.Second       = pc.GetSecond(helper);
            persianCalendarPart.Milisecond   = pc.GetMilliseconds(helper);
            persianCalendarPart.DayNumber    = GetDayOfWeekNumber(helper);
            return(persianCalendarPart);
        }
        public int DayOfYearToDayNum(int dayOfYear)
        {
            var      pc = MyPersianCalendar();
            DateTime dt = new DateTime(1391, 1, 1, pc);

            dt = dt.AddDays(dayOfYear - 1);
            var pers = new JalaliCalendar().GetPersianDateTime(dt);

            return(pers.DayNumber);
        }
        public int DayOfYearToMonthOfYear(int dayOfYear, int year)
        {
            var      pc = MyPersianCalendar();
            DateTime dt = new DateTime(year, 1, 1, pc);

            dt = dt.AddDays(dayOfYear - 1);
            var pers = new JalaliCalendar().GetPersianDateTime(dt);

            return(pers.Month);
        }
        public int DaysInYearsToDayNum(int daysInYears)
        {
            int year;
            int month;
            int day;

            DaysInYearsToDateParts(daysInYears, out year, out month, out day);
            var TheDate = new CronTabScheduler().JalaliToGregorian(year + "/" + month + "/" + day);
            var pers    = new JalaliCalendar().GetPersianDateTime(TheDate);

            return(pers.DayNumber);
        }
        public void SecondToDate(long seconds)
        {
            var      pc = MyPersianCalendar();
            DateTime dt = new DateTime(1, 1, 1, 1, 1, 1, 1, pc, DateTimeKind.Local);

            dt = dt.AddSeconds(seconds);
            var pers = new JalaliCalendar().GetPersianDateTime(dt);
            //month = pers.Month;
            //day = pers.Day;
            //hour = pers.Hour;
            //minute = pers.Minute;
        }
        public int GetDayInYears(JalaliCalendar j)
        {
            DateTime theDate = new DateTime(1, 1, 1);
            var      pc      = MyPersianCalendar();

            int totdalDays = 509147;

            for (int i = 1395; i < j.Year; i++)
            {
                totdalDays += pc.GetDaysInYear(i);
            }
            return(totdalDays + j.DayOfYear);
        }
        public void MinuteOfYearToDayAndMonth(int minuteOfYear, out int minute, out int hour, out int day, out int month)
        {
            var      pc = MyPersianCalendar();
            DateTime dt = new DateTime(1391, 1, 1, pc);

            dt = dt.AddMinutes(minuteOfYear);
            var pers = new JalaliCalendar().GetPersianDateTime(dt);

            month  = pers.Month;
            day    = pers.Day;
            hour   = pers.Hour;
            minute = pers.Minute;
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="occurances"></param>
        /// <param name="pattern"></param>
        private void RetrieveOccurances(DateTime startDate, DateTime endDate, List <DateTime> occurances, Pattern pattern)
        {
            if (pattern.UnitType == EnumUnitType.Secondly)
            {
                if (pattern.EveryNUnit > 0)
                {
                    for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalSeconds; i < TimeSpan.FromTicks(endDate.Ticks).TotalSeconds; i = i + pattern.EveryNUnit)
                    {
                        occurances.Add(new DateTime().AddSeconds(i));
                    }
                }
            }

            if (pattern.UnitType == EnumUnitType.Minutely)
            {
                for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalMinutes; i < TimeSpan.FromTicks(endDate.Ticks).TotalMinutes; i = i + pattern.EveryNUnit)
                {
                    occurances.Add(new DateTime().AddMinutes(i));
                }
            }

            if (pattern.UnitType == EnumUnitType.Hourly)
            {
                for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalHours; i < TimeSpan.FromTicks(endDate.Ticks).TotalHours; i = i + pattern.EveryNUnit)
                {
                    occurances.Add(new DateTime().AddHours(i));
                }
            }

            if (pattern.UnitType == EnumUnitType.Daily)
            {
                for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalHours; i < TimeSpan.FromTicks(endDate.Ticks).TotalHours; i = i + (pattern.Days[0] * 24))
                {
                    occurances.Add(new DateTime().AddHours(i + (pattern.Days[0] * 24)).Date.AddHours(pattern.Hour).AddMinutes(pattern.Minute));
                }
            }

            if (pattern.UnitType == EnumUnitType.Weekly)
            {
                for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalDays; i < TimeSpan.FromTicks(endDate.Ticks).TotalDays; i = i + 1)
                {
                    if (pattern.Days.Count >= 1)
                    {
                        var theDay = new DateTime(1, 1, 1).AddDays(i);
                        var jc     = new JalaliCalendar().GetPersianDateTime(theDay);
                        if (pattern.Days.Contains(jc.DayNumber))
                        {
                            occurances.Add(theDay.Date.AddHours(pattern.Hour).AddMinutes(pattern.Minute));
                        }
                    }
                }
            }

            if (pattern.UnitType == EnumUnitType.Monthly)
            {
                for (double i = TimeSpan.FromTicks(startDate.Ticks).TotalDays; i < TimeSpan.FromTicks(endDate.Ticks).TotalDays; i++)
                {
                    var theDay = new DateTime(1, 1, 1).AddDays(i);
                    var jc     = new JalaliCalendar().GetPersianDateTime(theDay);//  GregorianToJalali2(theDay);

                    if (pattern.Days.Count == 1 && pattern.Days[0] == -1)
                    {
                        if (jc.MonthTotalDays == jc.Day)
                        {
                            occurances.Add(theDay.Date.AddHours(pattern.Hour).AddMinutes(pattern.Minute));
                        }
                    }
                    if (pattern.Days.Any() && pattern.Months.Any())
                    {
                        if (pattern.Days.Contains(jc.Day) && pattern.Months.Contains(jc.Month))
                        {
                            occurances.Add(theDay.Date.AddHours(pattern.Hour).AddMinutes(pattern.Minute));
                        }
                    }
                    else
                    if (pattern.Days.Contains(jc.Day))
                    {
                        occurances.Add(theDay.Date.AddHours(pattern.Hour).AddMinutes(pattern.Minute));
                    }
                }
            }
        }
        public int GetMonthsInYears(JalaliCalendar j)
        {
            DateTime theDate = new DateTime(1, 1, 1);

            return((j.Year * 12) + j.Month);
        }