• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# LocalInstant类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中LocalInstant的典型用法代码示例。如果您正苦于以下问题:C# LocalInstant类的具体用法?C# LocalInstant怎么用?C# LocalInstant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LocalInstant类属于命名空间,在下文中一共展示了LocalInstant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: MinusOffset_Zero_IsNeutralElement

 public void MinusOffset_Zero_IsNeutralElement()
 {
     Instant sampleInstant = new Instant(1, 23456L);
     LocalInstant sampleLocalInstant = new LocalInstant(1, 23456L);
     Assert.AreEqual(sampleInstant, sampleLocalInstant.Minus(Offset.Zero));
     Assert.AreEqual(sampleInstant, sampleLocalInstant.MinusZeroOffset());
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:7,代码来源:LocalInstantTest.cs


示例2: SetValue

 internal override LocalInstant SetValue(LocalInstant localInstant, long value)
 {
     FieldUtils.VerifyValueBounds(this, value, min, max);
     long wrappedValue = WrappedField.GetInt64Value(localInstant);
     long remainder = wrappedValue >= 0 ? wrappedValue % divisor : (divisor - 1) + ((wrappedValue + 1) % divisor);
     return WrappedField.SetValue(localInstant, value * divisor + remainder);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:DividedDateTimeField.cs


示例3: GetValue_WithLocalInstant

 public void GetValue_WithLocalInstant()
 {
     LocalInstant when = new LocalInstant(987654321L);
     Assert.AreEqual(0, field.GetValue(new Duration(0L), when));
     Assert.AreEqual(12345, field.GetValue(new Duration(123456789L), when));
     Assert.AreEqual(-1, field.GetValue(new Duration(-12345L), when));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:PreciseDurationFieldTest.cs


示例4: GetZoneIntervals_WithinFirstSummer

 public void GetZoneIntervals_WithinFirstSummer()
 {
     var early = new LocalInstant(2000, 6, 1, 0, 0);
     var pair = TestZone.GetZoneIntervals(early);
     Assert.AreEqual("Summer", pair.EarlyInterval.Name);
     Assert.IsNull(pair.LateInterval);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:DaylightSavingTimeZoneTest.cs


示例5: SetValue

 internal override LocalInstant SetValue(LocalInstant localInstant, long value)
 {
     FieldUtils.VerifyValueBounds(this, value, 0, divisor - 1);
     int wrappedValue = WrappedField.GetValue(localInstant);
     int divided = wrappedValue >= 0 ? wrappedValue / divisor : ((wrappedValue + 1) / divisor) - 1;
     return WrappedField.SetValue(localInstant, divided * divisor + value);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:RemainderDateTimeField.cs


示例6: GetDifference

 internal override int GetDifference(LocalInstant minuendInstant, LocalInstant subtrahendInstant)
 {
     differences++;
     DiffFirstArg = minuendInstant;
     DiffSecondArg = subtrahendInstant;
     return 30;
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:MockCountingDurationField.cs


示例7: GetInt64Difference

        internal override long GetInt64Difference(LocalInstant minuendInstant, LocalInstant subtrahendInstant)
        {
            DateTimeField field = calendarSystem.Fields.WeekYear;

            if (minuendInstant < subtrahendInstant)
            {
                return -GetInt64Difference(subtrahendInstant, minuendInstant);
            }
            int minuendWeekYear = field.GetValue(minuendInstant);
            int subtrahendWeekYear = field.GetValue(subtrahendInstant);

            Duration minuendRemainder = field.Remainder(minuendInstant);
            Duration subtrahendRemainder = field.Remainder(subtrahendInstant);

            // Balance leap weekyear differences on remainders.
            if (subtrahendRemainder >= Week53Ticks && calendarSystem.GetWeeksInYear(minuendWeekYear) <= 52)
            {
                subtrahendRemainder -= Duration.OneWeek;
            }

            int difference = minuendWeekYear - subtrahendWeekYear;
            if (minuendRemainder < subtrahendRemainder)
            {
                difference--;
            }
            return difference;
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:27,代码来源:BasicWeekYearDurationField.cs


示例8: Add

 internal override LocalInstant Add(LocalInstant localInstant, int value)
 {
     int32Additions++;
     AddInstantArg = localInstant;
     AddValueArg = value;
     return new LocalInstant(localInstant.Ticks + value * unitTicks);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:7,代码来源:MockCountingDurationField.cs


示例9: GetInt64Value_WithLocalInstant

 public void GetInt64Value_WithLocalInstant()
 {
     LocalInstant when = new LocalInstant(56789L);
     Assert.AreEqual(0L, TicksDurationField.Instance.GetInt64Value(new Duration(0L), when));
     Assert.AreEqual(1234L, TicksDurationField.Instance.GetInt64Value(new Duration(1234L), when));
     Assert.AreEqual(-1234L, TicksDurationField.Instance.GetInt64Value(new Duration(-1234L), when));
     Assert.AreEqual(int.MaxValue + 1L, TicksDurationField.Instance.GetInt64Value(new Duration(int.MaxValue + 1L), when));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:8,代码来源:TicksDurationFieldTest.cs


示例10: SetValue

 internal override LocalInstant SetValue(LocalInstant localInstant, long value)
 {
     FieldUtils.VerifyValueBounds(this, value, 1, GetMaximumValue());
     if (calendarSystem.GetYear(localInstant) <= 0)
     {
         value = 1 - value;
     }
     return base.SetValue(localInstant, value);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:GJYearOfEraDateTimeField.cs


示例11: SetValue

 internal override LocalInstant SetValue(LocalInstant localInstant, long value)
 {
     FieldUtils.VerifyValueBounds(this, value, 0, GetMaximumValue());
     if (WrappedField.GetValue(localInstant) < 0)
     {
         value = -value;
     }
     return base.SetValue(localInstant, value);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:IsoYearOfEraDateTimeField.cs


示例12: FromDateTime

 public void FromDateTime()
 {
     LocalInstant expected = new LocalInstant(2011, 08, 18, 20, 53);
     foreach (DateTimeKind kind in Enum.GetValues(typeof(DateTimeKind)))
     {
         DateTime x = new DateTime(2011, 08, 18, 20, 53, 0, kind);
         LocalInstant actual = LocalInstant.FromDateTime(x);
         Assert.AreEqual(expected, actual);
     }
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:10,代码来源:LocalInstantTest.cs


示例13: GetValue_DelegatesToGetInt64Value

        public void GetValue_DelegatesToGetInt64Value()
        {
            var field = new StubDateTimeField();
            var arg = new LocalInstant(60);

            field.GetValue(arg);

            Assert.That(field.GetInt64ValueWasCalled, Is.True);
            Assert.That(field.GetInt64ValueArg, Is.EqualTo(arg));
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:10,代码来源:DateTimeFieldTest.cs


示例14: Equality

        public void Equality()
        {
            LocalInstant equal = new LocalInstant(1, 100L);
            LocalInstant different1 = new LocalInstant(1, 200L);
            LocalInstant different2 = new LocalInstant(2, 100L);

            TestHelper.TestEqualsStruct(equal, equal, different1);
            TestHelper.TestOperatorEquality(equal, equal, different1);

            TestHelper.TestEqualsStruct(equal, equal, different2);
            TestHelper.TestOperatorEquality(equal, equal, different2);
        }        
开发者ID:ivandrofly,项目名称:nodatime,代码行数:12,代码来源:LocalInstantTest.cs


示例15: Add

        /// <summary>
        /// Add the specified month to the specified time instant.
        /// The amount added may be negative.
        /// </summary>
        /// <param name="localInstant">The local instant to update</param>
        /// <param name="value">The months to add (can be negative).</param>
        /// <returns>The updated local instant</returns>
        /// <remarks>
        /// If the new month has less total days than the specified
        /// day of the month, this value is coerced to the nearest
        /// sane value. e.g.
        /// 07-31 - (1 month) = 06-30
        /// 03-31 - (1 month) = 02-28 or 02-29 depending
        /// </remarks>
        internal override LocalInstant Add(LocalInstant localInstant, int value)
        {
            // Keep the parameter name the same as the original declaration, but
            // use a more meaningful name in the method
            int months = value;
            if (months == 0)
            {
                return localInstant;
            }
            // Save the time part first
            long timePart = calendarSystem.GetTickOfDay(localInstant);
            // Get the year and month
            int thisYear = calendarSystem.GetYear(localInstant);
            int thisMonth = calendarSystem.GetMonthOfYear(localInstant, thisYear);

            // Do not refactor without careful consideration.
            // Order of calculation is important.

            int yearToUse;
            // Initially, monthToUse is zero-based
            int monthToUse = thisMonth - 1 + months;
            if (monthToUse >= 0)
            {
                yearToUse = thisYear + (monthToUse / monthsPerYear);
                monthToUse = (monthToUse % monthsPerYear) + 1;
            }
            else
            {
                yearToUse = thisYear + (monthToUse / monthsPerYear) - 1;
                monthToUse = Math.Abs(monthToUse);
                int remMonthToUse = monthToUse % monthsPerYear;
                // Take care of the boundary condition
                if (remMonthToUse == 0)
                {
                    remMonthToUse = monthsPerYear;
                }
                monthToUse = monthsPerYear - remMonthToUse + 1;
                // Take care of the boundary condition
                if (monthToUse == 1)
                {
                    yearToUse++;
                }
            }
            // End of do not refactor.

            // Quietly force DOM to nearest sane value.
            int dayToUse = calendarSystem.GetDayOfMonth(localInstant, thisYear, thisMonth);
            int maxDay = calendarSystem.GetDaysInMonth(yearToUse, monthToUse);
            dayToUse = Math.Min(dayToUse, maxDay);
            // Get proper date part, and return result
            long datePart = calendarSystem.GetYearMonthDayTicks(yearToUse, monthToUse, dayToUse);
            return new LocalInstant(datePart + timePart);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:67,代码来源:BasicMonthDurationField.cs


示例16: TestLocalInstantOperators

        public void TestLocalInstantOperators()
        {
            const long diff = TestTime2 - TestTime1;

            var time1 = new LocalInstant(TestTime1);
            var time2 = new LocalInstant(TestTime2);
            Duration duration = time2 - time1;

            Assert.AreEqual(diff, duration.Ticks);
            Assert.AreEqual(TestTime2, (time1 + duration).Ticks);
            Assert.AreEqual(TestTime1, (time2 - duration).Ticks);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:12,代码来源:LocalInstantTest.cs


示例17: AddWrapField

        internal override LocalInstant AddWrapField(LocalInstant localInstant, int value)
        {
            if (value == 0)
            {
                return localInstant;
            }

            int thisYear = calendarSystem.GetYear(localInstant);
            int wrappedYear = FieldUtils.GetWrappedValue(thisYear, value, calendarSystem.MinYear, calendarSystem.MaxYear);

            return SetValue(localInstant, wrappedYear);
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:12,代码来源:BasicYearDateTimeField.cs


示例18: SetValue

        internal override LocalInstant SetValue(LocalInstant localInstant, long value)
        {
            FieldUtils.VerifyValueBounds(this, value, MinimumValue, max);

            int month = (int)value;
            int thisYear = calendarSystem.GetYear(localInstant);
            int thisDom = calendarSystem.GetDayOfMonth(localInstant, thisYear);
            int maxDom = calendarSystem.GetDaysInMonth(thisYear, month);
            if (thisDom > maxDom)
            {
                // Quietly force DOM to nearest sane value.
                thisDom = maxDom;
            }
            return new LocalInstant(calendarSystem.GetYearMonthDayTicks(thisYear, month, thisDom) + calendarSystem.GetTickOfDay(localInstant));
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:15,代码来源:BasicMonthOfYearDateTimeField.cs


示例19: SetValue

        internal override LocalInstant SetValue(LocalInstant localInstant, long value)
        {
            FieldUtils.VerifyValueBounds(this, value, BeforeCommonEraIndex, CommonEraIndex);

            int oldEra = GetValue(localInstant);
            if (oldEra != value)
            {
                int year = calendarSystem.GetYear(localInstant);
                return calendarSystem.SetYear(localInstant, -year);
            }
            else
            {
                return localInstant;
            }
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:15,代码来源:GJEraDateTimeField.cs


示例20: GetYearDifference

        internal override long GetYearDifference(LocalInstant minuendInstant, LocalInstant subtrahendInstant)
        {
            // Optimized implementation due to fixed months
            int minuendYear = GetYear(minuendInstant);
            int subtrahendYear = GetYear(subtrahendInstant);

            // Inlined remainder method to avoid duplicate calls to get.
            long minuendRem = minuendInstant.Ticks - GetYearTicks(minuendYear);
            long subtrahendRem = subtrahendInstant.Ticks - GetYearTicks(subtrahendYear);

            int difference = minuendYear - subtrahendYear;
            if (minuendRem < subtrahendRem)
            {
                difference--;
            }
            return difference;
        }
开发者ID:manirana007,项目名称:NodaTime,代码行数:17,代码来源:BasicFixedMonthCalendarSystem.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# LocalReport类代码示例发布时间:2022-05-24
下一篇:
C# LocalDeclarationKind类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap