コード例 #1
0
 /// <summary>Returns the number of days in the specified month in the specified year 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="era">An integer that represents the era. </param>
 /// <returns>The number of days in the specified month in the specified year in the specified era.</returns>
 /// <exception cref="T:System.ArgumentOutOfRangeException">
 ///         <paramref name="era" /> is outside the range supported by the calendar. -or-
 ///         <paramref name="year" /> is outside the range supported by the calendar.-or-
 ///         <paramref name="month" /> is outside the range supported by the calendar. </exception>
 // Token: 0x06002F4E RID: 12110 RVA: 0x000B5554 File Offset: 0x000B3754
 public override int GetDaysInMonth(int year, int month, int era)
 {
     this.CheckYearEraRange(year, era);
     JulianCalendar.CheckMonthRange(month);
     int[] array = (year % 4 == 0) ? JulianCalendar.DaysToMonth366 : JulianCalendar.DaysToMonth365;
     return(array[month] - array[month - 1]);
 }
コード例 #2
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));
        }
コード例 #3
0
 // Token: 0x06002F44 RID: 12100 RVA: 0x000B521C File Offset: 0x000B341C
 internal void CheckYearEraRange(int year, int era)
 {
     JulianCalendar.CheckEraRange(era);
     if (year <= 0 || year > this.MaxYear)
     {
         throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, this.MaxYear));
     }
 }
コード例 #4
0
 /// <summary>Determines whether the specified date in the specified era is a leap day.</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="era">An integer that represents the era. </param>
 /// <returns>
 ///     <see langword="true" /> if the specified day is a leap day; otherwise, <see langword="false" />.</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="era" /> is outside the range supported by the calendar. </exception>
 // Token: 0x06002F55 RID: 12117 RVA: 0x000B55E2 File Offset: 0x000B37E2
 public override bool IsLeapDay(int year, int month, int day, int era)
 {
     JulianCalendar.CheckMonthRange(month);
     if (this.IsLeapYear(year, era))
     {
         JulianCalendar.CheckDayRange(year, month, day);
         return(month == 2 && day == 29);
     }
     JulianCalendar.CheckDayRange(year, month, day);
     return(false);
 }
コード例 #5
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"));
 }
コード例 #6
0
ファイル: SunriseEquation.cs プロジェクト: Antexa/Albedo
        private static double CurrentJulianDate()
        {
            JulianCalendar cal = new JulianCalendar();
            int isJanFeb = (14 - cal.GetMonth(DateTime.UtcNow)) / 12;
            int years = cal.GetYear(DateTime.UtcNow) + 4800 - isJanFeb;
            int monthsMod = cal.GetMonth(DateTime.UtcNow) + (12 * isJanFeb) - 3;

            double dayNumber =
                cal.GetDayOfMonth(DateTime.UtcNow)
                + Math.Floor((double)(153 * monthsMod + 2) / 5)
                + 365 * years + Math.Floor((double)years / 4) - 32083;

            double julianDate = dayNumber
                + ((double)cal.GetHour(DateTime.UtcNow) - 12) / 24
                + (double)cal.GetMinute(DateTime.UtcNow) / 1440
                + (double)cal.GetSecond(DateTime.UtcNow) / 86400;

            return julianDate;
        }
コード例 #7
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));
        }
コード例 #8
0
ファイル: Calendars.cs プロジェクト: johnhhm/corefx
 public static void JulianTest()
 {
     JulianCalendar jc = new JulianCalendar();
     Assert.False(jc.IsLeapYear(1999));
 }
コード例 #9
0
 /// <summary>Determines whether the specified month in the specified year in the specified era is a leap month.</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="era">An integer that represents the era. </param>
 /// <returns>This method always returns <see langword="false" />, unless overridden by a derived class.</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="era" /> is outside the range supported by the calendar. </exception>
 // Token: 0x06002F57 RID: 12119 RVA: 0x000B561D File Offset: 0x000B381D
 public override bool IsLeapMonth(int year, int month, int era)
 {
     this.CheckYearEraRange(year, era);
     JulianCalendar.CheckMonthRange(month);
     return(false);
 }
コード例 #10
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));
 }
コード例 #11
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));
 }
コード例 #12
0
	protected override void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
	}
コード例 #13
0
ファイル: CalendarTest.cs プロジェクト: GirlD/mono
	public void GetLeapMonth ()
	{
		GregorianCalendar gc = new GregorianCalendar ();
		Assert.AreEqual (0, gc.GetLeapMonth (2007), "#1-1");
		Assert.AreEqual (0, gc.GetLeapMonth (2008), "#1-2");
		Assert.AreEqual (0, gc.GetLeapMonth (2100), "#1-3");
		Assert.AreEqual (0, gc.GetLeapMonth (2000), "#1-4");

		JulianCalendar jc = new JulianCalendar ();
		Assert.AreEqual (0, jc.GetLeapMonth (2007), "#2-1");
		Assert.AreEqual (0, jc.GetLeapMonth (2008), "#2-2");
		Assert.AreEqual (0, jc.GetLeapMonth (2100), "#2-3");
		Assert.AreEqual (0, jc.GetLeapMonth (2000), "#2-4");
		Assert.AreEqual (0, jc.GetLeapMonth (2009), "#2-5");
		Assert.AreEqual (0, jc.GetLeapMonth (2010), "#2-6");

		HebrewCalendar hc = new HebrewCalendar ();
		// 3rd, 6th, 8th, 11th 14th and 17th year in every 19 are leap.
		// 5339 % 19 = 0.
		Assert.AreEqual (0, hc.GetLeapMonth (5343), "#3-1");
		Assert.AreEqual (0, hc.GetLeapMonth (5344), "#3-2");
		Assert.AreEqual (7, hc.GetLeapMonth (5345), "#3-3");
		Assert.AreEqual (0, hc.GetLeapMonth (5346), "#3-4");
		Assert.AreEqual (7, hc.GetLeapMonth (5347), "#3-5");
		Assert.AreEqual (0, hc.GetLeapMonth (5348), "#3-6");
		Assert.AreEqual (0, hc.GetLeapMonth (5349), "#3-7");

		ThaiBuddhistCalendar tc = new ThaiBuddhistCalendar ();
		Assert.AreEqual (0, tc.GetLeapMonth (2520), "#4-1");
		Assert.AreEqual (0, tc.GetLeapMonth (2521), "#4-2");
		Assert.AreEqual (0, tc.GetLeapMonth (2522), "#4-3");
		Assert.AreEqual (0, tc.GetLeapMonth (2523), "#4-4");

		ChineseLunisolarCalendar cc = new ChineseLunisolarCalendar ();
		Assert.AreEqual (0, cc.GetLeapMonth (2000), "#5-1");
		Assert.AreEqual (5, cc.GetLeapMonth (2001), "#5-2");
		Assert.AreEqual (0, cc.GetLeapMonth (2002), "#5-3");
		Assert.AreEqual (0, cc.GetLeapMonth (2003), "#5-4");
		Assert.AreEqual (3, cc.GetLeapMonth (2004), "#5-5");
		Assert.AreEqual (0, cc.GetLeapMonth (2005), "#5-6");
		Assert.AreEqual (8, cc.GetLeapMonth (2006), "#5-7");
		Assert.AreEqual (0, cc.GetLeapMonth (2007), "#5-8");
		Assert.AreEqual (0, cc.GetLeapMonth (2008), "#5-9");
		Assert.AreEqual (6, cc.GetLeapMonth (2009), "#5-10");
		Assert.AreEqual (0, cc.GetLeapMonth (2010), "#5-11");
		Assert.AreEqual (0, cc.GetLeapMonth (2011), "#5-12");
		Assert.AreEqual (5, cc.GetLeapMonth (2012), "#5-13");
		Assert.AreEqual (0, cc.GetLeapMonth (2013), "#5-14");
		Assert.AreEqual (10, cc.GetLeapMonth (2014), "#5-15");
		Assert.AreEqual (0, cc.GetLeapMonth (2015), "#5-16");
		Assert.AreEqual (0, cc.GetLeapMonth (2016), "#5-17");
		Assert.AreEqual (7, cc.GetLeapMonth (2017), "#5-18");
		Assert.AreEqual (0, cc.GetLeapMonth (2018), "#5-19");
		Assert.AreEqual (0, cc.GetLeapMonth (2019), "#5-20");

		KoreanLunisolarCalendar kc = new KoreanLunisolarCalendar ();
		Assert.AreEqual (0, kc.GetLeapMonth (2000), "#6-1");
		Assert.AreEqual (5, kc.GetLeapMonth (2001), "#6-2");
		Assert.AreEqual (0, kc.GetLeapMonth (2002), "#6-3");
		Assert.AreEqual (0, kc.GetLeapMonth (2003), "#6-4");
		Assert.AreEqual (3, kc.GetLeapMonth (2004), "#6-5");
		Assert.AreEqual (0, kc.GetLeapMonth (2005), "#6-6");
		Assert.AreEqual (8, kc.GetLeapMonth (2006), "#6-7");
		Assert.AreEqual (0, kc.GetLeapMonth (2007), "#6-8");
		Assert.AreEqual (0, kc.GetLeapMonth (2008), "#6-9");
		Assert.AreEqual (6, kc.GetLeapMonth (2009), "#6-10");
		Assert.AreEqual (0, kc.GetLeapMonth (2010), "#6-11");
		Assert.AreEqual (0, kc.GetLeapMonth (2011), "#6-12");
		Assert.AreEqual (4, kc.GetLeapMonth (2012)); // off from cn by 1, "#6-13");
		Assert.AreEqual (0, kc.GetLeapMonth (2013), "#6-14");
		Assert.AreEqual (10, kc.GetLeapMonth (2014), "#6-15");
		Assert.AreEqual (0, kc.GetLeapMonth (2015), "#6-16");
		Assert.AreEqual (0, kc.GetLeapMonth (2016), "#6-17");
		Assert.AreEqual (6, kc.GetLeapMonth (2017)); // off from cn by 1, "#6-18");
		Assert.AreEqual (0, kc.GetLeapMonth (2018), "#6-19");
		Assert.AreEqual (0, kc.GetLeapMonth (2019), "#6-20");
	}
コード例 #14
0
ファイル: CalendarTest.cs プロジェクト: GirlD/mono
	protected void SetUp() {
		gcal = new GregorianCalendar();
		jucal = new JulianCalendar();
		hical = new HijriCalendar();
		hecal = new HebrewCalendar();
		jacal = new JapaneseCalendar();
		tacal = new TaiwanCalendar();
		kcal = new KoreanCalendar();
		tbcal = new ThaiBuddhistCalendar();
		acal = new Calendar[] {
			gcal, jucal, hical, hecal, jacal,
			tacal, kcal, tbcal};
#if NET_2_0
		clcal = new ChineseLunisolarCalendar ();
		tlcal = new TaiwanLunisolarCalendar ();
		jlcal = new JapaneseLunisolarCalendar ();
		klcal = new KoreanLunisolarCalendar ();
#endif
	}
コード例 #15
0
ファイル: DateTimeFormatter.cs プロジェクト: AndrewM-/Peygir
        public DateTimeFormatter(string dateTimePattern, string calendarName, string amDesignator, string pmDesignator)
        {
            Calendar calendar = null;
            switch (calendarName)
            {
                case "ChineseLunisolarCalendar":
                    calendar = new ChineseLunisolarCalendar();
                    break;

                case "GregorianCalendar":
                    calendar = new GregorianCalendar();
                    break;

                case "HebrewCalendar":
                    calendar = new HebrewCalendar();
                    break;

                case "HijriCalendar":
                    calendar = new HijriCalendar();
                    break;

                case "JapaneseCalendar":
                    calendar = new JapaneseCalendar();
                    break;

                case "JapaneseLunisolarCalendar":
                    calendar = new JapaneseLunisolarCalendar();
                    break;

                case "JulianCalendar":
                    calendar = new JulianCalendar();
                    break;

                case "KoreanCalendar":
                    calendar = new KoreanCalendar();
                    break;

                case "KoreanLunisolarCalendar":
                    calendar = new KoreanLunisolarCalendar();
                    break;

                case "PersianCalendar":
                    calendar = new PersianCalendar();
                    break;

                case "TaiwanCalendar":
                    calendar = new TaiwanCalendar();
                    break;

                case "TaiwanLunisolarCalendar":
                    calendar = new TaiwanLunisolarCalendar();
                    break;

                case "ThaiBuddhistCalendar":
                    calendar = new ThaiBuddhistCalendar();
                    break;

                case "UmAlQuraCalendar":
                    calendar = new UmAlQuraCalendar();
                    break;
            }

            Initialize(dateTimePattern, calendar, amDesignator, pmDesignator);
        }