コード例 #1
0
        /// <summary>
        /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>String</c>.
        /// </summary>
        /// <param name="date"></param>
        /// <returns>Gregorian DateTime representation in string format of evaluated Jalali Date.</returns>
        static public string ToGregorianDate(PersianDate date)
        {
            int iJYear  = date.Year;
            int iJMonth = date.Month;
            int iJDay   = date.Day;

            //Continue
            int iTotalDays, iGYear, iGMonth, iGDay;
            int Div4, Div100, Div400;
            int iGDays;
            int i, leap;

            iTotalDays = JalaliDays(iJYear, iJMonth, iJDay);
            iTotalDays = iTotalDays + GYearOff;
            iGYear     = (int)(iTotalDays / (Solar - 0.25 / 33));

            Div4   = iGYear / 4;
            Div100 = iGYear / 100;
            Div400 = iGYear / 400;

            iGDays = iTotalDays - (365 * iGYear) - (Div4 - Div100 + Div400);
            iGYear = iGYear + 1;

            if (iGDays == 0)
            {
                iGYear--;
                if (GLeap(iGYear) == 1)
                {
                    iGDays = 366;
                }
                else
                {
                    iGDays = 365;
                }
            }
            else
            {
                if (iGDays == 366 && GLeap(iGYear) != 1)
                {
                    iGDays = 1;
                    iGYear++;
                }
            }

            leap = GLeap(iGYear);
            for (i = 0; i <= 12; i++)
            {
                if (iGDays <= GDayTable[leap, i])
                {
                    break;
                }

                iGDays = iGDays - GDayTable[leap, i];
            }

            iGMonth = i + 1;
            iGDay   = iGDays;

            return(toDouble(iGMonth) + "/" + toDouble(iGDay) + "/" + iGYear + " " + toDouble(date.Hour) + ":" + toDouble(date.Minute) + ":" + toDouble(date.Second));
        }
コード例 #2
0
        public static PersianDate StartOfWeek(this PersianDate dateTime)
        {
            var dt   = dateTime.ToDateTime();
            var diff = GetStartOfWeekDiff(dt);
            var pc   = CultureHelper.PersianCalendar;

            return(pc.AddDays(dt, -diff));
        }
コード例 #3
0
        public static PersianDate EndOfMonth(this PersianDate dateTime)
        {
            var dt        = dateTime.ToDateTime();
            var start     = StartOfMonth(dateTime).ToDateTime();
            var pc        = CultureHelper.PersianCalendar;
            var nextMonth = pc.AddMonths(start, 1);

            return(pc.AddDays(nextMonth, -1));
        }
コード例 #4
0
ファイル: PersianDateConverter.cs プロジェクト: iranEdu/irQm
        internal static string DayOfWeek(PersianDate date)
        {
            if (!date.IsNull)
            {
                var dt = ToGregorianDateTime(date);
                return(DayOfWeek(dt));
            }

            return(string.Empty);
        }
コード例 #5
0
        /// <summary>
        /// Converts a Gregorian Date of type <c>String</c> and a <c>TimeSpan</c> into a Persian Date.
        /// </summary>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public static PersianDate ToPersianDate(string date, TimeSpan time)
        {
            PersianDate pd = ToPersianDate(date);

            pd.Hour   = time.Hours;
            pd.Minute = time.Minutes;
            pd.Second = time.Seconds;

            return(pd);
        }
コード例 #6
0
ファイル: PersianDateConverter.cs プロジェクト: iranEdu/irQm
        ///<summary>
        ///</summary>
        public static DateTime ToMiladi(PersianDate date)
        {
            var jyear  = date.Year;
            var jmonth = date.Month;
            var jday   = date.Day;

            //Continue
            int i;

            var totalDays = JalaliDays(jyear, jmonth, jday);

            totalDays = totalDays + GYearOff;

            var gyear  = (int)(totalDays / (Solar - 0.25 / 33));
            var Div4   = gyear / 4;
            var Div100 = gyear / 100;
            var Div400 = gyear / 400;
            var gdays  = totalDays - (365 * gyear) - (Div4 - Div100 + Div400);

            gyear = gyear + 1;

            if (gdays == 0)
            {
                gyear--;
                gdays = GLeap(gyear) == 1 ? 366 : 365;
            }
            else
            {
                if (gdays == 366 && GLeap(gyear) != 1)
                {
                    gdays = 1;
                    gyear++;
                }
            }

            var leap = GLeap(gyear);

            for (i = 0; i <= 12; i++)
            {
                if (gdays <= GDayTable[leap, i])
                {
                    break;
                }

                gdays = gdays - GDayTable[leap, i];
            }

            var iGMonth = i + 1;
            var iGDay   = gdays;


            return(new DateTime(gyear, iGMonth, iGDay, date.Hour, date.Minute, date.Second, new GregorianCalendar()));
        }
コード例 #7
0
ファイル: PersianDateConverter.cs プロジェクト: iranEdu/irQm
        /// <summary>
        /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>String</c>.
        /// </summary>
        /// <param name="date"></param>
        /// <returns>Gregorian DateTime representation in string format of evaluated Jalali Date.</returns>
        public static string ToGregorianDate(PersianDate date)
        {
            var jyear  = date.Year;
            var jmonth = date.Month;
            var jday   = date.Day;

            //Continue
            int i;

            var totalDays = JalaliDays(jyear, jmonth, jday);

            totalDays = totalDays + GYearOff;

            var gyear  = (int)(totalDays / (Solar - 0.25 / 33));
            var Div4   = gyear / 4;
            var Div100 = gyear / 100;
            var Div400 = gyear / 400;
            var gdays  = totalDays - (365 * gyear) - (Div4 - Div100 + Div400);

            gyear = gyear + 1;

            if (gdays == 0)
            {
                gyear--;
                gdays = GLeap(gyear) == 1 ? 366 : 365;
            }
            else
            {
                if (gdays == 366 && GLeap(gyear) != 1)
                {
                    gdays = 1;
                    gyear++;
                }
            }

            var leap = GLeap(gyear);

            for (i = 0; i <= 12; i++)
            {
                if (gdays <= GDayTable[leap, i])
                {
                    break;
                }

                gdays = gdays - GDayTable[leap, i];
            }

            var iGMonth = i + 1;
            var iGDay   = gdays;

            return(Util.toDouble(iGMonth) + "/" + Util.toDouble(iGDay) + "/" + gyear + " " + Util.toDouble(date.Hour) + ":" + Util.toDouble(date.Minute) + ":" + Util.toDouble(date.Second));
        }
コード例 #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PersianDate fr = new FarsiLibrary.Utils.PersianDate();
            string month = fr.Month.ToString();
            string day = (fr.Day - 1).ToString();
            if (month.Length == 1) month = "0" + month;
            if (day.Length == 1) day = "0" + day;

            TextBox3.Text = fr.Year.ToString() + "/" + month + "/" + day;
        }
    }
コード例 #9
0
    static public string PersianDate(DateTime dt)
    {
        FarsiLibrary.Utils.PersianDate pd = FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(dt.ToString());

        string d, m;

        d = pd.Day.ToString();
        m = pd.Month.ToString();

        if (d.Length == 1)
        {
            d = "0" + d;
        }

        if (m.Length == 1)
        {
            m = "0" + m;
        }

        return(pd.Year.ToString() + "/" + m + "/" + d);
    }
コード例 #10
0
    static public string CurrentPersianDateWithoutSlash()
    {
        FarsiLibrary.Utils.PersianDate pd = FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(DateTime.Now.ToString());

        string d, m;

        d = pd.Day.ToString();
        m = pd.Month.ToString();

        if (d.Length == 1)
        {
            d = "0" + d;
        }

        if (m.Length == 1)
        {
            m = "0" + m;
        }

        return(pd.Year.ToString() + m + d);
    }
コード例 #11
0
ファイル: PersianDateConverter.cs プロジェクト: iranEdu/irQm
        /// <summary>
        /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>DateTime</c> class.
        /// </summary>
        /// <param name="date">Date to evaluate</param>
        /// <returns>Gregorian DateTime representation of evaluated Jalali Date.</returns>
        public static DateTime ToGregorianDateTime(string date)
        {
            var pd = new PersianDate(date);

            return(DateTime.Parse(ToGregorianDate(pd), CultureHelper.NeutralCulture));
        }
コード例 #12
0
 static public string CurrentPersianDateName()
 {
     FarsiLibrary.Utils.PersianDate pd = FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(DateTime.Now.ToString());
     return(pd.LocalizedWeekDayName);
 }
コード例 #13
0
 static public int CurrentPersianDay()
 {
     FarsiLibrary.Utils.PersianDate pd = FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(DateTime.Now.ToString());
     return(pd.Day);
 }
コード例 #14
0
 public static PersianDate Combine(this PersianDate datePart, PersianDate timePart)
 {
     return(new PersianDate(datePart.Year, datePart.Month, datePart.Day, timePart.Hour, timePart.Minute, timePart.Second, timePart.Millisecond));
 }
コード例 #15
0
 public static DateTime ToGregorianDateTime(PersianDate date)
 {
     return(Convert.ToDateTime(ToGregorianDate(date)));
 }
コード例 #16
0
 public static PersianDate StartOfMonth(this PersianDate dateTime)
 {
     return(new PersianDate(dateTime.Year, dateTime.Month, 1));
 }
コード例 #17
0
 /// <summary>
 /// Converts the PersianDate to a DateTime equivalant.
 /// </summary>
 /// <param name="persianDate"></param>
 /// <returns></returns>
 public static DateTime ToDateTime(this PersianDate persianDate)
 {
     return(PersianDateConverter.ToGregorianDateTime(persianDate));
 }
コード例 #18
0
ファイル: PersianDateConverter.cs プロジェクト: iranEdu/irQm
 public static DateTime ToGregorianDateTime(PersianDate date)
 {
     return(DateTime.Parse(ToGregorianDate(date), CultureHelper.NeutralCulture));
 }
コード例 #19
0
        /// <summary>
        /// Converts a Persian Date of type <c>String</c> to Gregorian Date of type <c>DateTime</c> class.
        /// </summary>
        /// <param name="date">Date to evaluate</param>
        /// <returns>Gregorian DateTime representation of evaluated Jalali Date.</returns>
        public static DateTime ToGregorianDateTime(string date)
        {
            PersianDate pd = new PersianDate(date);

            return(Convert.ToDateTime(ToGregorianDate(pd)));
        }
コード例 #20
0
        public void AddOrDecreaseDate(int intValue)
        {
            try
            {
                FarsiLibrary.Utils.PersianDate fdt = new FarsiLibrary.Utils.PersianDate();
                fdt.Year  = Convert.ToInt32(this.Text.Substring(0, 4));
                fdt.Month = Convert.ToInt32(this.Text.Substring(5, 2));
                fdt.Day   = Convert.ToInt32(this.Text.Substring(8, 2));
                if ((this.SelectionStart < 5))
                {
                    // Year
                    if (((fdt.Month == 11) && ((intValue > 0) && (fdt.Day > 29))))
                    {
                        fdt.Day   = 29;
                        this.Text = fdt.ToString("d");
                    }

                    string str = Convert.ToString((fdt.Year + intValue));
                    this.Text            = this.Text.Remove(0, 4).Insert(0, str.Substring((str.Length - 4)));
                    this.SelectionStart  = 0;
                    this.SelectionLength = 4;
                }
                else if ((this.SelectionStart < 8))
                {
                    // Month
                    int intMonth = (fdt.Month + intValue);
                    Math.DivRem(intMonth, 12, out intMonth);
                    if ((intMonth == 0))
                    {
                        intMonth = 12;
                    }
                    else if ((intMonth < 0))
                    {
                        intMonth = Math.Abs(intMonth);
                    }

                    if (((intMonth == 12) &&
                         (fdt.Day > 29)))
                    {
                        fdt.Day = 29;
                    }
                    else if (((intMonth > 6) &&
                              (fdt.Day == 31)))
                    {
                        fdt.Day = 30;
                    }

                    fdt.Month            = intMonth;
                    this.Text            = this.Text.Remove(0, 10).Insert(0, fdt.ToString("d"));
                    this.SelectionStart  = 5;
                    this.SelectionLength = 2;
                }
                else if ((this.SelectionStart < 11))
                {
                    // Day
                    this.Text            = this.Text.Remove(0, 10).Insert(0, FarsiLibrary.Utils.PersianDateConverter.ToPersianDate(fdt.ToDateTime().AddDays(intValue)).ToString("d"));
                    this.SelectionStart  = 8;
                    this.SelectionLength = 2;
                }
                else if ((this.SelectionStart < 14))
                {
                    // Hour
                    int intHour = Convert.ToInt32(this.Text.Substring(11, 2));
                    intHour = (intHour + intValue);
                    intHour = (intHour > 12) ? 1 : (intHour < 1) ? 12 : intHour;

                    this.Text            = this.Text.Remove(11, 2).Insert(11, string.Format("{0:00}", intHour));
                    this.SelectionStart  = 11;
                    this.SelectionLength = 2;
                }
                else if ((this.SelectionStart < 17))
                {
                    int intMinute = Convert.ToInt32(this.Text.Substring(14, 2));
                    intMinute = (intMinute - (intMinute % 5));
                    intMinute = (intMinute + (intValue * 5));
                    intMinute = (intMinute >= 60) ? 0 : (intMinute < 0) ? 55 : intMinute;

                    this.Text            = this.Text.Remove(14, 2).Insert(14, string.Format("{0:00}", intMinute));
                    this.SelectionStart  = 14;
                    this.SelectionLength = 2;
                }
                else if ((this.SelectionStart <= 20))
                {
                    this.Text            = this.Text.Remove(17, 3).Insert(17, (this.Text.Contains("ب.ظ") ? "ق.ظ" : "ب.ظ"));
                    this.SelectionStart  = 17;
                    this.SelectionLength = 3;
                }
            }
            catch { }
        }