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


C# LocalDateTime.Plus方法代码示例

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


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

示例1: GetAnswer

 public Answer GetAnswer(Question question)
 {
     var cityToken = question.GetToken<CityToken>();
     var dateToken = question.GetToken<DateToken>();
     int? year = null;
     if (dateToken != null) year = dateToken.Year;
     DaylightSavingInformation daylightSavingInfo;
     if (year.HasValue)
     {
         var firstDateInTheYear = new LocalDateTime(year.Value, 1, 1, 0, 0).InZone(DateTimeZoneProviders.Tzdb[cityToken.City.Timezone], Resolvers.LenientResolver);
         var firstZoneIntervalInTheYear = firstDateInTheYear.GetZoneInterval();
         if (firstZoneIntervalInTheYear.IsoLocalEnd.Year > 10000) {
             daylightSavingInfo = DaylightSavingInformation.CreateWithNoDaylightSavings();
         }
         else
         {
             var firstDateInTheNextZoneInterval = firstDateInTheYear.Plus(firstZoneIntervalInTheYear.Duration).Plus(Duration.FromMilliseconds(1));
             daylightSavingInfo = GetDaylightSavingInfo(firstDateInTheNextZoneInterval);
         }
     }
     else
     {
         daylightSavingInfo = GetDaylightSavingInfo(cityToken.GetCurrentTime());
     }
     var answerText = GetFormattedDaylightSavingInfo(daylightSavingInfo, cityToken.City);
     return new Answer(question, true, true, answerText);
 }
开发者ID:darkosancanin,项目名称:naturaldatetime_web,代码行数:27,代码来源:WhenDaylightSavingsStartStopInCityQuestionHandler.cs

示例2: Addition_Duration

        public void Addition_Duration()
        {
            const int minutes = 23;
            const int hours = 3;
            const int milliseconds = 40000;
            const long seconds = 321;
            const long nanoseconds = 12345;
            const long ticks = 5432112345;

            // Test all three approaches... not bothering to check a different calendar,
            // but we'll use two different offsets.
            OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
            Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9);
            OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));
            Assert.AreEqual(expected, start + duration);
            Assert.AreEqual(expected, start.Plus(duration));
            Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));

            Assert.AreEqual(start + Duration.FromHours(hours), start.PlusHours(hours));
            Assert.AreEqual(start + Duration.FromHours(-hours), start.PlusHours(-hours));

            Assert.AreEqual(start + Duration.FromMinutes(minutes), start.PlusMinutes(minutes));
            Assert.AreEqual(start + Duration.FromMinutes(-minutes), start.PlusMinutes(-minutes));

            Assert.AreEqual(start + Duration.FromSeconds(seconds), start.PlusSeconds(seconds));
            Assert.AreEqual(start + Duration.FromSeconds(-seconds), start.PlusSeconds(-seconds));

            Assert.AreEqual(start + Duration.FromMilliseconds(milliseconds), start.PlusMilliseconds(milliseconds));
            Assert.AreEqual(start + Duration.FromMilliseconds(-milliseconds), start.PlusMilliseconds(-milliseconds));

            Assert.AreEqual(start + Duration.FromTicks(ticks), start.PlusTicks(ticks));
            Assert.AreEqual(start + Duration.FromTicks(-ticks), start.PlusTicks(-ticks));

            Assert.AreEqual(start + Duration.FromNanoseconds(nanoseconds), start.PlusNanoseconds(nanoseconds));
            Assert.AreEqual(start + Duration.FromNanoseconds(-nanoseconds), start.PlusNanoseconds(-nanoseconds));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:36,代码来源:OffsetDateTimeTest.cs

示例3: Operator_MethodEquivalents

 public void Operator_MethodEquivalents()
 {
     LocalDateTime start = new LocalDateTime(2011, 1, 1, 15, 25, 30, 100, 5000);
     Period period = Period.FromHours(1) + Period.FromDays(1);
     LocalDateTime end = start + period;
     Assert.AreEqual(start + period, LocalDateTime.Add(start, period));
     Assert.AreEqual(start + period, start.Plus(period));
     Assert.AreEqual(start - period, LocalDateTime.Subtract(start, period));
     Assert.AreEqual(start - period, start.Minus(period));
     Assert.AreEqual(period, end - start);
     Assert.AreEqual(period, LocalDateTime.Subtract(end, start));
     Assert.AreEqual(period, end.Minus(start));
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:13,代码来源:LocalDateTimeTest.Pseudomutators.cs

示例4: Addition_Duration

 public void Addition_Duration()
 {
     // Test all three approaches... not bothering to check a different calendar,
     // but we'll use two different offsets.
     OffsetDateTime start = new LocalDateTime(2014, 08, 14, 6, 51).WithOffset(Offset.FromHours(1));
     Duration duration = Duration.FromHours(8) + Duration.FromMinutes(9);
     OffsetDateTime expected = new LocalDateTime(2014, 08, 14, 15, 0).WithOffset(Offset.FromHours(1));
     Assert.AreEqual(expected, start + duration);
     Assert.AreEqual(expected, start.Plus(duration));
     Assert.AreEqual(expected, OffsetDateTime.Add(start, duration));
 }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:11,代码来源:OffsetDateTimeTest.cs

示例5: Plus_FullPeriod

 public void Plus_FullPeriod()
 {
     LocalDateTime start = new LocalDateTime(2011, 4, 2, 12, 15, 8);
     var period = new PeriodBuilder { Years = 1, Months = 2, Weeks = 3, Days = 4, Hours = 5, Minutes = 6,
                                      Seconds = 7, Milliseconds = 8, Ticks = 9 }.Build();
     var actual = start.Plus(period);
     var expected = new LocalDateTime(2012, 6, 27, 17, 21, 15, 8, 9);
     Assert.AreEqual(expected, actual);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:9,代码来源:LocalDateTimeTest.Pseudomutators.cs


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