DateToTicks() private method

private DateToTicks ( int year, int month, int day ) : long
year int
month int
day int
return long
Example #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));
        }
Example #2
0
 /// <summary>Returns a <see cref="T:System.DateTime" /> that is set to the specified date and time in the specified era.</summary>
 /// <param name="year">An integer that represents the year. </param>
 /// <param name="month">An integer from 1 to 12 that represents the month. </param>
 /// <param name="day">An integer from 1 to 31 that represents the day. </param>
 /// <param name="hour">An integer from 0 to 23 that represents the hour. </param>
 /// <param name="minute">An integer from 0 to 59 that represents the minute. </param>
 /// <param name="second">An integer from 0 to 59 that represents the second. </param>
 /// <param name="millisecond">An integer from 0 to 999 that represents the millisecond. </param>
 /// <param name="era">An integer that represents the era. </param>
 /// <returns>The <see cref="T:System.DateTime" /> that is set to the specified date and time in the current era.</returns>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///         <paramref name="year" /> is outside the range supported by the calendar.-or-
 ///         <paramref name="month" /> is outside the range supported by the calendar.-or-
 ///         <paramref name="day" /> is outside the range supported by the calendar.-or-
 ///         <paramref name="hour" /> is less than zero or greater than 23.-or-
 ///         <paramref name="minute" /> is less than zero or greater than 59.-or-
 ///         <paramref name="second" /> is less than zero or greater than 59.-or-
 ///         <paramref name="millisecond" /> is less than zero or greater than 999. -or-
 ///         <paramref name="era" /> is outside the range supported by the calendar. </exception>
 // Token: 0x06002F59 RID: 12121 RVA: 0x000B5640 File Offset: 0x000B3840
 public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
 {
     this.CheckYearEraRange(year, era);
     JulianCalendar.CheckMonthRange(month);
     JulianCalendar.CheckDayRange(year, month, day);
     if (millisecond < 0 || millisecond >= 1000)
     {
         throw new ArgumentOutOfRangeException("millisecond", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, 999));
     }
     if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
     {
         return(new DateTime(JulianCalendar.DateToTicks(year, month, day) + new TimeSpan(0, hour, minute, second, millisecond).Ticks));
     }
     throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"));
 }
Example #3
0
        /// <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));
        }