GetDatePart() private method

private GetDatePart ( long ticks, int part ) : int
ticks long
part int
return int
コード例 #1
0
        /// <summary>Returns a <see cref="T:System.DateTime" /> that is the specified number of months away from the specified <see cref="T:System.DateTime" />.</summary>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param>
        /// <param name="months">The number of months to add. </param>
        /// <returns>The <see cref="T:System.DateTime" /> that results from adding the specified number of months to the specified <see cref="T:System.DateTime" />.</returns>
        /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///         <paramref name="months" /> is less than -120000.-or-
        ///         <paramref name="months" /> is greater than 120000. </exception>
        // Token: 0x06002F49 RID: 12105 RVA: 0x000B53F8 File Offset: 0x000B35F8
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), -120000, 120000));
            }
            int num  = JulianCalendar.GetDatePart(time.Ticks, 0);
            int num2 = JulianCalendar.GetDatePart(time.Ticks, 2);
            int num3 = JulianCalendar.GetDatePart(time.Ticks, 3);
            int num4 = num2 - 1 + months;

            if (num4 >= 0)
            {
                num2 = num4 % 12 + 1;
                num += num4 / 12;
            }
            else
            {
                num2 = 12 + (num4 + 1) % 12;
                num += (num4 - 11) / 12;
            }
            int[] array = (num % 4 == 0 && (num % 100 != 0 || num % 400 == 0)) ? JulianCalendar.DaysToMonth366 : JulianCalendar.DaysToMonth365;
            int   num5  = array[num2] - array[num2 - 1];

            if (num3 > num5)
            {
                num3 = num5;
            }
            long ticks = JulianCalendar.DateToTicks(num, num2, num3) + time.Ticks % 864000000000L;

            Calendar.CheckAddResult(ticks, this.MinSupportedDateTime, this.MaxSupportedDateTime);
            return(new DateTime(ticks));
        }
コード例 #2
0
ファイル: juliancalendar.cs プロジェクト: wwkkww1983/ZJCredit
        /// <summary>返回与指定 <see cref="T:System.DateTime" /> 相距指定月数的 <see cref="T:System.DateTime" />。</summary>
        /// <returns>将指定的月数添加到指定的 <see cref="T:System.DateTime" /> 中时得到的 <see cref="T:System.DateTime" />。</returns>
        /// <param name="time">
        /// <see cref="T:System.DateTime" />,将向其添加月数。</param>
        /// <param name="months">要添加的月数。</param>
        /// <exception cref="T:System.ArgumentException">结果 <see cref="T:System.DateTime" /> 超出了支持的范围。</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="months" /> 小于 -120000。- 或 -<paramref name="months" /> 大于 120000。</exception>
        public override DateTime AddMonths(DateTime time, int months)
        {
            if (months < -120000 || months > 120000)
            {
                throw new ArgumentOutOfRangeException("months", string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), (object)-120000, (object)120000));
            }
            int datePart1 = JulianCalendar.GetDatePart(time.Ticks, 0);
            int datePart2 = JulianCalendar.GetDatePart(time.Ticks, 2);
            int day       = JulianCalendar.GetDatePart(time.Ticks, 3);
            int num1      = datePart2 - 1 + months;
            int month;
            int year;

            if (num1 >= 0)
            {
                month = num1 % 12 + 1;
                year  = datePart1 + num1 / 12;
            }
            else
            {
                month = 12 + (num1 + 1) % 12;
                year  = datePart1 + (num1 - 11) / 12;
            }
            int[] numArray = year % 4 != 0 || year % 100 == 0 && year % 400 != 0 ? JulianCalendar.DaysToMonth365 : JulianCalendar.DaysToMonth366;
            int   num2     = numArray[month] - numArray[month - 1];

            if (day > num2)
            {
                day = num2;
            }
            long     ticks = JulianCalendar.DateToTicks(year, month, day) + time.Ticks % 864000000000L;
            DateTime supportedDateTime1 = this.MinSupportedDateTime;
            DateTime supportedDateTime2 = this.MaxSupportedDateTime;

            Calendar.CheckAddResult(ticks, supportedDateTime1, supportedDateTime2);
            return(new DateTime(ticks));
        }
コード例 #3
0
 /// <summary>Returns the year in the specified <see cref="T:System.DateTime" />.</summary>
 /// <param name="time">The <see cref="T:System.DateTime" /> to read. </param>
 /// <returns>An integer that represents the year in <paramref name="time" />.</returns>
 // Token: 0x06002F54 RID: 12116 RVA: 0x000B55D3 File Offset: 0x000B37D3
 public override int GetYear(DateTime time)
 {
     return(JulianCalendar.GetDatePart(time.Ticks, 0));
 }
コード例 #4
0
 /// <summary>Returns the month in the specified <see cref="T:System.DateTime" />.</summary>
 /// <param name="time">The <see cref="T:System.DateTime" /> to read. </param>
 /// <returns>An integer from 1 to 12 that represents the month in <paramref name="time" />.</returns>
 // Token: 0x06002F51 RID: 12113 RVA: 0x000B55A8 File Offset: 0x000B37A8
 public override int GetMonth(DateTime time)
 {
     return(JulianCalendar.GetDatePart(time.Ticks, 2));
 }