コード例 #1
0
 /// <summary>
 /// Returns a value indicating whether this instance is equal to the specified PersianDateTime instance.
 /// </summary>
 /// <param name="value">A PersianDateTime instance to compare to this instance.</param>
 /// <returns>true if the value parameter equals the value of this instance; otherwise, false.</returns>
 public bool Equals(PersianDateTime value)
 {
     if (object.ReferenceEquals(value, null))
     {
         return(false);
     }
     return(_dateTime.Equals(value._dateTime));
 }
コード例 #2
0
        /// <summary>
        /// Returns a new PersianDateTime that adds the specified number of years to the value of this instance.
        /// </summary>
        /// <param name="value">A number of years. The value parameter can be negative or positive.</param>
        /// <returns>An object whose value is the sum of the date and time represented by this instance and the number of years represented by value.</returns>
        public PersianDateTime AddYears(int value)
        {
            var newYear = Year + value;

            var daysInNewMonth = PersianDateTime.GetDaysInMonth(newYear, Month);
            var newDay         = daysInNewMonth < Day ? daysInNewMonth : Day;

            return(new PersianDateTime(Year + value, Month, Day).Add(TimeOfDay));
        }
コード例 #3
0
        /// <summary>
        /// Returns a new PersianDateTime that adds the specified number of months to the value of this instance.
        /// </summary>
        /// <param name="value">A number of months. The months parameter can be negative or positive.</param>
        /// <returns>An object whose value is the sum of the date and time represented by this instance and months.</returns>
        public PersianDateTime AddMonths(int value)
        {
            var months = Month + value;

            var newYear  = Year + (months > 0 ? (months - 1) / 12 : months / 12 - 1);
            var newMonth = months > 0 ? (months - 1) % 12 + 1 : months % 12 + 12;

            var daysInNewMonth = PersianDateTime.GetDaysInMonth(newYear, newMonth);
            var newDay         = daysInNewMonth < Day ? daysInNewMonth : Day;

            return(new PersianDateTime(newYear, newMonth, newDay).Add(TimeOfDay));
        }
コード例 #4
0
        public static string ToHijriJustHour(this DateTime value)
        {
            var pc = new PersianDateTime(value);

            return(pc.ToString("HH:mm"));
        }
コード例 #5
0
        public static string ToHijriFarsiWithHourAndMinute(this DateTime value)
        {
            var pc = new PersianDateTime(value);

            return(pc.ToString("dddd d MMMM yyyy ساعت HH:mm"));
        }
コード例 #6
0
        public static string ToHijriFarsiHourWithoutMinutes(this DateTime value)
        {
            var pc = new PersianDateTime(value);

            return(pc.ToString("ساعت HH"));
        }
コード例 #7
0
        public static string ToHijriFarsi(this DateTime value)
        {
            var pc = new PersianDateTime(value);

            return(pc.ToString("dddd d MMMM yyyy"));
        }