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


C# LocalInstant类代码示例

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


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


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