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


C# LocalDate.PlusDays方法代码示例

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


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

示例1: PlusDays_MonthBoundary

        public void PlusDays_MonthBoundary()
        {
            LocalDate start = new LocalDate(2011, 1, 26);
            LocalDate expected = new LocalDate(2011, 2, 3);
            Assert.AreEqual(expected, start.PlusDays(8));

            // Round-trip back across the boundary
            Assert.AreEqual(start, start.PlusDays(8).PlusDays(-8));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:9,代码来源:LocalDateTest.Pseudomutators.cs

示例2: PlusDays_SameMonth

        public void PlusDays_SameMonth()
        {
            LocalDate start = new LocalDate(2011, 1, 15);
            LocalDate expected = new LocalDate(2011, 1, 23);
            Assert.AreEqual(expected, start.PlusDays(8));

            expected = new LocalDate(2011, 1, 7);
            Assert.AreEqual(expected, start.PlusDays(-8));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:9,代码来源:LocalDateTest.Pseudomutators.cs

示例3: Constructor_WithDaysAndCalendar

 [TestCase(1981)] // Non-leap year in optimized period
 public void Constructor_WithDaysAndCalendar(int year)
 {
     LocalDate start = new LocalDate(year, 1, 1);
     int startDays = start.DaysSinceEpoch;
     for (int i = 0; i < 366; i++)
     {
         Assert.AreEqual(start.PlusDays(i), new LocalDate(startDays + i, CalendarSystem.Iso));
     }
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:10,代码来源:LocalDateTest.Construction.cs

示例4: IsoDayOfWeek_AroundEpoch

 public void IsoDayOfWeek_AroundEpoch()
 {
     // Test about couple of months around the Unix epoch. If that works, I'm confident the rest will.
     LocalDate date = new LocalDate(1969, 12, 1);
     for (int i = 0; i < 60; i++)
     {
         Assert.AreEqual(
             BclConversions.ToIsoDayOfWeek(date.AtMidnight().ToDateTimeUnspecified().DayOfWeek),
             date.IsoDayOfWeek);
         date = date.PlusDays(1);
     }
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:12,代码来源:LocalDateTest.BasicProperties.cs

示例5: MysteryTimeZones

        public void MysteryTimeZones()
        {
            var julianCalendar = CalendarSystem.Julian;
            var julianEpoch = new LocalDate(Era.BeforeCommon, 4713, 1, 1, julianCalendar);
            var sampleDate = julianEpoch.PlusDays(2475213);

            Console.WriteLine("Sample date in ISO calendar: {0}", sampleDate.WithCalendar(CalendarSystem.Iso));

            var zoneProvider = DateTimeZoneProviders.Tzdb;
            foreach (var id in zoneProvider.Ids)
            {
                var zone = zoneProvider[id];
                if (zone.AtStartOfDay(sampleDate).LocalDateTime.TimeOfDay != LocalTime.Midnight)
                {
                    Console.WriteLine(id);
                }
            }
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:18,代码来源:StackOverflowExamples.cs

示例6: GuessZoneIdByTransitionsUncached

        public void GuessZoneIdByTransitionsUncached(TimeZoneInfo bclZone)
        {
            // As of October 17th 2013, the Windows time zone database hasn't noticed that
            // Morocco delayed the DST transition in 2013, so we end up with UTC. It's
            // annoying, but it's not actually a code issue. Just ignore it for now. We
            // should check this periodically and remove the hack when it works again.
            // Likewise Libya has somewhat odd representation in the BCL. Worth looking at more closely later.
            if (bclZone.Id == "Morocco Standard Time" || bclZone.Id == "Libya Standard Time")
            {
                return;
            }
            string id = TzdbDateTimeZoneSource.Default.GuessZoneIdByTransitionsUncached(bclZone);

            // Unmappable zones may not be mapped, or may be mapped to something reasonably accurate.
            // We don't mind either way.
            if (!TzdbDateTimeZoneSource.Default.WindowsMapping.PrimaryMapping.ContainsKey(bclZone.Id))
            {
                return;
            }

            Assert.IsNotNull(id);
            var tzdbZone = TzdbDateTimeZoneSource.Default.ForId(id);

            var thisYear = SystemClock.Instance.GetCurrentInstant().InUtc().Year;
            LocalDate? lastIncorrectDate = null;
            Offset? lastIncorrectBclOffset = null;
            Offset? lastIncorrectTzdbOffset = null;

            int total = 0;
            int correct = 0;
            // From the start of this year to the end of next year, we should have an 80% hit rate or better.
            // That's stronger than the 70% we limit to in the code, because if it starts going between 70% and 80% we
            // should have another look at the algorithm. (And this is dealing with 80% of days, not 80% of transitions,
            // so it's not quite equivalent anyway.)
            for (var date = new LocalDate(thisYear, 1, 1); date.Year < thisYear + 2; date = date.PlusDays(1))
            {
                Instant startOfUtcDay = date.AtMidnight().InUtc().ToInstant();
                Offset tzdbOffset = tzdbZone.GetUtcOffset(startOfUtcDay);
                Offset bclOffset = Offset.FromTimeSpan(bclZone.GetUtcOffset(startOfUtcDay.ToDateTimeOffset()));
                if (tzdbOffset == bclOffset)
                {
                    correct++;
                }
                else
                {
                    // Useful for debugging (by having somewhere to put a breakpoint) as well as for the message.
                    lastIncorrectDate = date;
                    lastIncorrectBclOffset = bclOffset;
                    lastIncorrectTzdbOffset = tzdbOffset;
                }
                total++;
            }
            Assert.That(correct * 100.0 / total, Is.GreaterThanOrEqualTo(75.0),
                "Last incorrect date for {0} vs {1}: {2} (BCL: {3}; TZDB: {4})",
                bclZone.Id,
                id,
                lastIncorrectDate, lastIncorrectBclOffset, lastIncorrectTzdbOffset);
        }
开发者ID:GunwantSaini,项目名称:nodatime,代码行数:58,代码来源:TzdbDateTimeZoneSourceTest.cs

示例7: GuessZoneIdByTransitionsUncached

        public void GuessZoneIdByTransitionsUncached(TimeZoneInfo bclZone)
        {
            // As of April 21st 2016, the Windows time zone database hasn't caught up to
            // 2016d which includes: "America/Caracas switches from -0430 to -04 on 2016-05-01 at 02:30"
            // Still need to investigate Morocco...
            if (bclZone.Id == "Venezuela Standard Time" || bclZone.Id == "Morocco Standard Time")
            {
                return;
            }

            string id = TzdbDateTimeZoneSource.Default.GuessZoneIdByTransitionsUncached(bclZone);

            // Unmappable zones may not be mapped, or may be mapped to something reasonably accurate.
            // We don't mind either way.
            if (!TzdbDateTimeZoneSource.Default.WindowsMapping.PrimaryMapping.ContainsKey(bclZone.Id))
            {
                return;
            }

            Assert.IsNotNull(id, $"Unable to guess time zone for {bclZone.Id}");
            var tzdbZone = TzdbDateTimeZoneSource.Default.ForId(id);

            var thisYear = SystemClock.Instance.GetCurrentInstant().InUtc().Year;
            LocalDate? lastIncorrectDate = null;
            Offset? lastIncorrectBclOffset = null;
            Offset? lastIncorrectTzdbOffset = null;

            int total = 0;
            int correct = 0;
            // From the start of this year to the end of next year, we should have an 80% hit rate or better.
            // That's stronger than the 70% we limit to in the code, because if it starts going between 70% and 80% we
            // should have another look at the algorithm. (And this is dealing with 80% of days, not 80% of transitions,
            // so it's not quite equivalent anyway.)
            for (var date = new LocalDate(thisYear, 1, 1); date.Year < thisYear + 2; date = date.PlusDays(1))
            {
                Instant startOfUtcDay = date.AtMidnight().InUtc().ToInstant();
                Offset tzdbOffset = tzdbZone.GetUtcOffset(startOfUtcDay);
                Offset bclOffset = Offset.FromTimeSpan(bclZone.GetUtcOffset(startOfUtcDay.ToDateTimeOffset()));
                if (tzdbOffset == bclOffset)
                {
                    correct++;
                }
                else
                {
                    // Useful for debugging (by having somewhere to put a breakpoint) as well as for the message.
                    lastIncorrectDate = date;
                    lastIncorrectBclOffset = bclOffset;
                    lastIncorrectTzdbOffset = tzdbOffset;
                }
                total++;
            }
            Assert.That(correct * 100.0 / total, Is.GreaterThanOrEqualTo(75.0),
                "Last incorrect date for {0} vs {1}: {2} (BCL: {3}; TZDB: {4})",
                bclZone.Id,
                id,
                lastIncorrectDate, lastIncorrectBclOffset, lastIncorrectTzdbOffset);
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:57,代码来源:TzdbDateTimeZoneSourceTest.cs

示例8: PlusDays_EndOfFebruary_InLeapYear

 public void PlusDays_EndOfFebruary_InLeapYear()
 {
     LocalDate start = new LocalDate(2012, 2, 26);
     LocalDate expected = new LocalDate(2012, 3, 5);
     Assert.AreEqual(expected, start.PlusDays(8));
     // Round-trip back across the boundary
     Assert.AreEqual(start, start.PlusDays(8).PlusDays(-8));
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:8,代码来源:LocalDateTest.Pseudomutators.cs

示例9: PlusDays_LargeValue

 public void PlusDays_LargeValue()
 {
     LocalDate start = new LocalDate(2013, 2, 26);
     LocalDate expected = new LocalDate(2015, 2, 26);
     Assert.AreEqual(expected, start.PlusDays(365 * 2));
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:6,代码来源:LocalDateTest.Pseudomutators.cs

示例10: BclEquivalence

        public void BclEquivalence(
            [ValueSource(typeof(BclCalendars), nameof(BclCalendars.MappedCalendars))] Calendar calendar,
            [ValueSource(nameof(CalendarWeekRules))] CalendarWeekRule bclRule,
            [ValueSource(nameof(BclDaysOfWeek))] DayOfWeek firstDayOfWeek)
        {
            var nodaCalendar = BclCalendars.CalendarSystemForCalendar(calendar);
            var nodaRule = WeekYearRules.FromCalendarWeekRule(bclRule, firstDayOfWeek);
            var startYear = new LocalDate(2016, 1, 1).WithCalendar(nodaCalendar).Year;

            for (int year = startYear; year < startYear + 30; year++)
            {
                var startDate = new LocalDate(year, 1, 1, nodaCalendar).PlusDays(-15);
                for (int day = 0; day < 30; day++)
                {
                    var date = startDate.PlusDays(day);
                    var bclDate = date.ToDateTimeUnspecified();
                    var bclWeek = calendar.GetWeekOfYear(bclDate, bclRule, firstDayOfWeek);
                    // Weird... the BCL doesn't have a way of finding out which week-year we're in.
                    // We're starting at "start of year - 15 days", so a "small" week-of-year
                    // value means we're in "year", whereas a "large" week-of-year value means
                    // we're in the "year-1".
                    var bclWeekYear = bclWeek < 10 ? year : year - 1;

                    Assert.AreEqual(bclWeek, nodaRule.GetWeekOfWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(bclWeekYear, nodaRule.GetWeekYear(date), "Date: {0}", date);
                    Assert.AreEqual(date, nodaRule.GetLocalDate(bclWeekYear, bclWeek, date.IsoDayOfWeek, nodaCalendar),
                        "Week-year:{0}; Week: {1}; Day: {2}", bclWeekYear, bclWeek, date.IsoDayOfWeek);
                }
            }
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:30,代码来源:SimpleWeekYearRuleTest.cs


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