当前位置: 首页>>代码示例>>C#>>正文


C# LocalDate.WithCalendar方法代码示例

本文整理汇总了C#中LocalDate.WithCalendar方法的典型用法代码示例。如果您正苦于以下问题:C# LocalDate.WithCalendar方法的具体用法?C# LocalDate.WithCalendar怎么用?C# LocalDate.WithCalendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LocalDate的用法示例。


在下文中一共展示了LocalDate.WithCalendar方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ArithmeticExamples

 public void ArithmeticExamples(int persianYear, int gregorianYear, int gregorianDayOfMarch)
 {
     var persian = new LocalDate(persianYear, 1, 1, CalendarSystem.PersianArithmetic);
     var gregorian = persian.WithCalendar(CalendarSystem.Gregorian);
     Assert.AreEqual(gregorianYear, gregorian.Year);
     Assert.AreEqual(3, gregorian.Month);
     Assert.AreEqual(gregorianDayOfMarch, gregorian.Day);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:8,代码来源:PersianCalendarSystemTest.cs

示例2: WithCalendar

 public void WithCalendar()
 {
     LocalDate isoEpoch = new LocalDate(1970, 1, 1);
     LocalDate julianEpoch = isoEpoch.WithCalendar(CalendarSystem.GetJulianCalendar(4));
     Assert.AreEqual(1969, julianEpoch.Year);
     Assert.AreEqual(12, julianEpoch.MonthOfYear);
     Assert.AreEqual(19, julianEpoch.DayOfMonth);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:8,代码来源:LocalDateTest.Conversion.cs

示例3: Equals_DifferentCalendars

 public void Equals_DifferentCalendars()
 {
     LocalDate start1 = new LocalDate(2000, 1, 1);
     LocalDate end1 = new LocalDate(2001, 6, 19);
     // This is a really, really similar calendar to ISO, but we do distinguish.
     // TODO: Should we?
     LocalDate start2 = start1.WithCalendar(CalendarSystem.Gregorian);
     LocalDate end2 = end1.WithCalendar(CalendarSystem.Gregorian);
     var interval1 = new DateInterval(start1, end1, false);
     var interval2 = new DateInterval(start2, end2, false);
     Assert.AreNotEqual(interval1, interval2);
     Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode());
     Assert.IsFalse(interval1 == interval2);
     Assert.IsTrue(interval1 != interval2);
     Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:16,代码来源:DateIntervalTest.cs

示例4: Equals_DifferentCalendars

 public void Equals_DifferentCalendars()
 {
     LocalDate start1 = new LocalDate(2000, 1, 1);
     LocalDate end1 = new LocalDate(2001, 6, 19);
     // This is a really, really similar calendar to ISO - the dates could differ by week of year,
     // but that's all.
     LocalDate start2 = start1.WithCalendar(CalendarSystem.GetGregorianCalendar(1));
     LocalDate end2 = end1.WithCalendar(CalendarSystem.GetGregorianCalendar(1));
     var interval1 = new DateInterval(start1, end1, false);
     var interval2 = new DateInterval(start2, end2, false);
     Assert.AreNotEqual(interval1, interval2);
     Assert.AreNotEqual(interval1.GetHashCode(), interval2.GetHashCode());
     Assert.IsFalse(interval1 == interval2);
     Assert.IsTrue(interval1 != interval2);
     Assert.IsFalse(interval1.Equals(interval2)); // IEquatable implementation
 }
开发者ID:jackthorley,项目名称:nodatime,代码行数:16,代码来源:DateIntervalTest.cs

示例5: TestLeapCycle

        /// <summary>
        /// Converts each day in a full leap cycle (for coverage of different scenarios) to the ISO
        /// calendar and back. This exercises fetching the number of days since the epoch and getting
        /// a year/month/day *from* a number of days.
        /// </summary>
        private static void TestLeapCycle(CalendarSystem calendar)
        {
            for (int year = 5400; year < 5419; year++)
            {
#if !V1
                int maxMonth = calendar.GetMonthsInYear(year);
#else
                int maxMonth = calendar.GetMaxMonth(year);
#endif
                for (int month = 1; month <= maxMonth; month++)
                {
                    int maxDay = calendar.GetDaysInMonth(year, month);
                    for (int day = 1; day <= maxDay; day++)
                    {
                        var date = new LocalDate(year, month, day, calendar);
                        date.WithCalendar(CalendarSystem.Iso).WithCalendar(calendar).Consume();
                    }
                }
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:25,代码来源:HebrewCalendarBenchmarks.cs

示例6: BclUsesAstronomicalEpoch

        public void BclUsesAstronomicalEpoch()
        {
            Calendar hijri = BclCalendars.Hijri;
            DateTime bclDirect = hijri.ToDateTime(1, 1, 1, 0, 0, 0, 0);

            CalendarSystem julianCalendar = CalendarSystem.Julian;
            LocalDate julianIslamicEpoch = new LocalDate(622, 7, 15, julianCalendar);
            LocalDate isoIslamicEpoch = julianIslamicEpoch.WithCalendar(CalendarSystem.Iso);
            DateTime bclFromNoda = isoIslamicEpoch.AtMidnight().ToDateTimeUnspecified();
            Assert.AreEqual(bclDirect, bclFromNoda);
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:11,代码来源:IslamicCalendarSystemTest.cs

示例7: FridayEpoch

        public void FridayEpoch()
        {
            CalendarSystem fridayEpochCalendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base16, IslamicEpoch.Civil);
            CalendarSystem julianCalendar = CalendarSystem.Julian;

            LocalDate fridayEpoch = new LocalDate(1, 1, 1, fridayEpochCalendar);
            LocalDate fridayEpochJulian = new LocalDate(622, 7, 16, julianCalendar);
            Assert.AreEqual(fridayEpochJulian, fridayEpoch.WithCalendar(julianCalendar));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:9,代码来源:IslamicCalendarSystemTest.cs

示例8: ThursdayEpoch

        public void ThursdayEpoch()
        {
            CalendarSystem thursdayEpochCalendar = CalendarSystem.IslamicBcl;
            CalendarSystem julianCalendar = CalendarSystem.Julian;

            LocalDate thursdayEpoch = new LocalDate(1, 1, 1, thursdayEpochCalendar);
            LocalDate thursdayEpochJulian = new LocalDate(622, 7, 15, julianCalendar);
            Assert.AreEqual(thursdayEpochJulian, thursdayEpoch.WithCalendar(julianCalendar));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:9,代码来源:IslamicCalendarSystemTest.cs

示例9: WithCalendar_OutOfRange

 public void WithCalendar_OutOfRange()
 {
     LocalDate start = new LocalDate(1, 1, 1);
     Assert.Throws<ArgumentOutOfRangeException>(() => start.WithCalendar(CalendarSystem.PersianSimple));
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:5,代码来源:LocalDateTest.Conversion.cs

示例10: BclThroughHistory

        public void BclThroughHistory()
        {
            Calendar hijri = new HijriCalendar();
            DateTime bclDirect = new DateTime(1, 1, 1, 0, 0, 0, 0, hijri, DateTimeKind.Unspecified);

            CalendarSystem islamicCalendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base16, IslamicEpoch.Astronomical);
            CalendarSystem julianCalendar = CalendarSystem.GetJulianCalendar(4);
            LocalDate julianIslamicEpoch = new LocalDate(622, 7, 15, julianCalendar);
            LocalDate islamicDate = julianIslamicEpoch.WithCalendar(islamicCalendar);

            for (int i = 0; i < 9000 * 365; i++)
            {
                Assert.AreEqual(bclDirect, islamicDate.LocalDateTime.ToDateTimeUnspecified());
                Assert.AreEqual(hijri.GetYear(bclDirect), islamicDate.Year, i.ToString());
                Assert.AreEqual(hijri.GetMonth(bclDirect), islamicDate.MonthOfYear);
                Assert.AreEqual(hijri.GetDayOfMonth(bclDirect), islamicDate.DayOfMonth);
                bclDirect = hijri.AddDays(bclDirect, 1);
                islamicDate = islamicDate.PlusDays(1);
            }
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:20,代码来源:IslamicCalendarTest.cs

示例11: BclUsesAstronomicalEpoch

        public void BclUsesAstronomicalEpoch()
        {
            Calendar hijri = new HijriCalendar();
            DateTime bclDirect = new DateTime(1, 1, 1, 0, 0, 0, 0, hijri, DateTimeKind.Unspecified);

            CalendarSystem julianCalendar = CalendarSystem.GetJulianCalendar(4);
            LocalDate julianIslamicEpoch = new LocalDate(622, 7, 15, julianCalendar);
            LocalDate isoIslamicEpoch = julianIslamicEpoch.WithCalendar(CalendarSystem.Iso);
            DateTime bclFromNoda = isoIslamicEpoch.LocalDateTime.ToDateTimeUnspecified();
            Assert.AreEqual(bclDirect, bclFromNoda);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:11,代码来源:IslamicCalendarTest.cs

示例12: ThursdayEpoch

        public void ThursdayEpoch()
        {
            CalendarSystem thursdayEpochCalendar = CalendarSystem.GetIslamicCalendar(IslamicLeapYearPattern.Base16, IslamicEpoch.Astronomical);
            CalendarSystem julianCalendar = CalendarSystem.GetJulianCalendar(4);

            LocalDate thursdayEpoch = new LocalDate(1, 1, 1, thursdayEpochCalendar);
            LocalDate thursdayEpochJulian = new LocalDate(622, 7, 15, julianCalendar);
            Assert.AreEqual(thursdayEpochJulian, thursdayEpoch.WithCalendar(julianCalendar));
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:IslamicCalendarTest.cs

示例13: HebrewCalendar

        public void HebrewCalendar(int year, IsoDayOfWeek expectedFirstDay,
            int isoYear, int isoMonth, int isoDay, // Mostly for documentation
            int expectedWeeks, int expectedWeekYearOfFirstDay, int expectedWeekOfWeekYearOfFirstDay)
        {
            var civilDate = new LocalDate(year, 1, 1, HebrewCivil);
            var rule = WeekYearRules.Iso;
            Assert.AreEqual(expectedFirstDay, civilDate.IsoDayOfWeek);
            Assert.AreEqual(civilDate.WithCalendar(CalendarSystem.Iso), new LocalDate(isoYear, isoMonth, isoDay));
            Assert.AreEqual(expectedWeeks, rule.GetWeeksInWeekYear(year, HebrewCivil));
            Assert.AreEqual(expectedWeekYearOfFirstDay, rule.GetWeekYear(civilDate));
            Assert.AreEqual(expectedWeekOfWeekYearOfFirstDay, rule.GetWeekOfWeekYear(civilDate));
            Assert.AreEqual(civilDate,
                rule.GetLocalDate(expectedWeekYearOfFirstDay, expectedWeekOfWeekYearOfFirstDay, expectedFirstDay, HebrewCivil));

            // The scriptural month numbering system should have the same week-year and week-of-week-year.
            var scripturalDate = civilDate.WithCalendar(HebrewScriptural);
            Assert.AreEqual(expectedWeeks, rule.GetWeeksInWeekYear(year, HebrewScriptural));
            Assert.AreEqual(expectedWeekYearOfFirstDay, rule.GetWeekYear(scripturalDate));
            Assert.AreEqual(expectedWeekOfWeekYearOfFirstDay, rule.GetWeekOfWeekYear(scripturalDate));
            Assert.AreEqual(scripturalDate,
                rule.GetLocalDate(expectedWeekYearOfFirstDay, expectedWeekOfWeekYearOfFirstDay, expectedFirstDay, HebrewScriptural));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:22,代码来源:SimpleWeekYearRuleTest.cs


注:本文中的LocalDate.WithCalendar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。