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


C# LocalDate.AtMidnight方法代码示例

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


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

示例1: BclThroughHistory_Scriptural

        public void BclThroughHistory_Scriptural()
        {
            var bcl = BclCalendars.Hebrew;
            var noda = CalendarSystem.HebrewScriptural;

            // The min supported date/time starts part way through the year
            var minYear = bcl.GetYear(bcl.MinSupportedDateTime) + 1;
            // The max supported date/time ends part way through the year
            var maxYear = bcl.GetYear(bcl.MaxSupportedDateTime) - 1;

            // Can't use BclEquivalenceHelper for this one, because of the month conversions.
            for (int year = minYear; year <= maxYear; year++)
            {
                int months = bcl.GetMonthsInYear(year);
                Assert.AreEqual(months, noda.GetMonthsInYear(year));
                for (int civilMonth = 1; civilMonth <= months; civilMonth++)
                {
                    int scripturalMonth = HebrewMonthConverter.CivilToScriptural(year, civilMonth);
                    Assert.AreEqual(bcl.GetDaysInMonth(year, civilMonth), noda.GetDaysInMonth(year, scripturalMonth),
                        "Year: {0}; Month: {1} (civil)", year, civilMonth);
                    for (int day = 1; day < bcl.GetDaysInMonth(year, civilMonth); day++)
                    {
                        DateTime bclDate = bcl.ToDateTime(year, civilMonth, day, 0, 0, 0, 0);
                        LocalDate nodaDate = new LocalDate(year, scripturalMonth, day, noda);
                        Assert.AreEqual(bclDate, nodaDate.AtMidnight().ToDateTimeUnspecified(), "{0}-{1}-{2}", year, scripturalMonth, day);
                        Assert.AreEqual(nodaDate, LocalDateTime.FromDateTime(bclDate, noda).Date);
                        Assert.AreEqual(year, nodaDate.Year);
                        Assert.AreEqual(scripturalMonth, nodaDate.Month);
                        Assert.AreEqual(day, nodaDate.Day);
                    }
                }
            }
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:33,代码来源:HebrewCalendarSystemTest.cs

示例2: Transitions2000To2010

        public void Transitions2000To2010()
        {
            // These were fetched with Joda Time 1.6.2, which definitely uses the new rules.
            var expectedDates = new[]
            {
                new LocalDate(2000, 3, 30), // Thursday morning
                new LocalDate(2001, 3, 29), // Thursday morning
                new LocalDate(2002, 3, 29), // Friday morning from here onwards
                new LocalDate(2003, 3, 28),
                new LocalDate(2004, 3, 26),
                new LocalDate(2005, 4, 1),
                new LocalDate(2006, 3, 31),
                new LocalDate(2007, 3, 30),
                new LocalDate(2008, 3, 28),
                new LocalDate(2009, 3, 27),
                new LocalDate(2010, 3, 26)
            };

            for (int year = 2000; year <= 2010; year++)
            {
                LocalDate summer = new LocalDate(year, 6, 1);
                var intervalPair = Jordan.MapLocal(summer.AtMidnight());
                Assert.AreEqual(1, intervalPair.Count);
                Assert.AreEqual(expectedDates[year - 2000], intervalPair.EarlyInterval.IsoLocalStart.Date);
            }
        }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:26,代码来源:JordanTest.cs

示例3: 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

示例4: SampleDateBclCompatibility

        public void SampleDateBclCompatibility()
        {
            Calendar hijri = BclCalendars.Hijri;
            DateTime bclDirect = hijri.ToDateTime(1302, 10, 15, 0, 0, 0, 0);

            CalendarSystem islamicCalendar = CalendarSystem.IslamicBcl;
            LocalDate iso = new LocalDate(1302, 10, 15, islamicCalendar);
            DateTime bclFromNoda = iso.AtMidnight().ToDateTimeUnspecified();
            Assert.AreEqual(bclDirect, bclFromNoda);
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:10,代码来源:IslamicCalendarSystemTest.cs

示例5: AtMidnight

 public void AtMidnight()
 {
     LocalDate date = new LocalDate(2011, 6, 29);
     LocalDateTime expected = new LocalDateTime(2011, 6, 29, 0, 0, 0);
     Assert.AreEqual(expected, date.AtMidnight());
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:6,代码来源:LocalDateTest.Conversion.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: TicksFrom

 /// <summary>
 /// Gets the number of ticks a period represents based on a given start date.
 /// </summary>
 /// <param name="period">The period.</param>
 /// <param name="start">The start.</param>
 /// <returns></returns>
 public static long TicksFrom([NotNull] this Period period, LocalDate start)
 {
     return Period.Between(start.AtMidnight(), start.AtMidnight() + period, PeriodUnits.Ticks).Ticks;
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:10,代码来源:LocalHelpers.cs

示例9: TicksTo

 /// <summary>
 /// Gets the number of ticks a between a start and end date.
 /// </summary>
 /// <param name="start">The start.</param>
 /// <param name="end">The end.</param>
 /// <returns></returns>
 public static long TicksTo(this LocalDate start, LocalDate end)
 {
     return Period.Between(start.AtMidnight(), end.AtMidnight(), PeriodUnits.Ticks).Ticks;
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:10,代码来源:LocalHelpers.cs


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