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

C# Instant类代码示例

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

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



Instant类属于命名空间,在下文中一共展示了Instant类的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: GetZoneInterval

        /// <inheritdoc />
        public override ZoneInterval GetZoneInterval(Instant instant)
        {
            int lower = 0; // Inclusive
            int upper = Intervals.Count; // Exclusive

            while (lower < upper)
            {
                int current = (lower + upper) / 2;
                var candidate = Intervals[current];
                if (candidate.HasStart && candidate.Start > instant)
                {
                    upper = current;
                }
                else if (candidate.HasEnd && candidate.End <= instant)
                {
                    lower = current + 1;
                }
                else
                {
                    return candidate;
                }
            }
            // Note: this would indicate a bug. The time zone is meant to cover the whole of time.
            throw new InvalidOperationException(string.Format("Instant {0} did not exist in time zone {1}", instant, Id));
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:26,代码来源:MultiTransitionDateTimeZone.cs


示例3: GetZoneInterval

        /// <summary>
        /// Gets the zone offset period for the given instant.
        /// </summary>
        /// <param name="instant">The Instant to find.</param>
        /// <returns>The ZoneInterval including the given instant.</returns>
        public override ZoneInterval GetZoneInterval(Instant instant)
        {
            if (tailZone != null && instant >= tailZoneStart)
            {
                // Clamp the tail zone interval to start at the end of our final period, if necessary, so that the
                // join is seamless.
                ZoneInterval intervalFromTailZone = tailZone.GetZoneInterval(instant);
                return intervalFromTailZone.RawStart < tailZoneStart ? firstTailZoneInterval : intervalFromTailZone;
            }
            
            int lower = 0; // Inclusive
            int upper = periods.Length; // Exclusive

            while (lower < upper)
            {
                int current = (lower + upper) / 2;
                var candidate = periods[current];
                if (candidate.RawStart > instant)
                {
                    upper = current;
                }
                // Safe to use RawEnd, as it's just for the comparison.
                else if (candidate.RawEnd <= instant)
                {
                    lower = current + 1;
                }
                else
                {
                    return candidate;
                }
            }
            // Note: this would indicate a bug. The time zone is meant to cover the whole of time.
            throw new InvalidOperationException($"Instant {instant} did not exist in time zone {Id}");
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:39,代码来源:PrecalculatedDateTimeZone.cs


示例4: SingleTransitionZone

 /// <summary>
 /// Creates a zone with a single transition between two offsets.
 /// </summary>
 /// <param name="transitionPoint">The transition point as an <see cref="Instant"/>.</param>
 /// <param name="offsetBefore">The offset of local time from UTC before the transition.</param>
 /// <param name="offsetAfter">The offset of local time from UTC before the transition.</param>
 public SingleTransitionZone(Instant transitionPoint, Offset offsetBefore, Offset offsetAfter)
     : base("Single", false, Offset.Min(offsetBefore, offsetAfter), Offset.Max(offsetBefore, offsetAfter))
 {
     earlyInterval = new ZoneInterval("Single-Early", Instant.MinValue, transitionPoint,
         offsetBefore, Offset.Zero);
     lateInterval = new ZoneInterval("Single-Late", transitionPoint, Instant.MaxValue,
         offsetAfter, Offset.Zero);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:14,代码来源:SingleTransitionZone.cs


示例5: SingleTransitionDateTimeZone

 /// <summary>
 /// Creates a zone with a single transition between two offsets.
 /// </summary>
 /// <param name="transitionPoint">The transition point as an <see cref="Instant"/>.</param>
 /// <param name="offsetBefore">The offset of local time from UTC before the transition.</param>
 /// <param name="offsetAfter">The offset of local time from UTC before the transition.</param>
 /// <param name="id">ID for the newly created time zone.</param>
 public SingleTransitionDateTimeZone(Instant transitionPoint, Offset offsetBefore, Offset offsetAfter, string id)
     : base(id, false, Offset.Min(offsetBefore, offsetAfter), Offset.Max(offsetBefore, offsetAfter))
 {
     EarlyInterval = new ZoneInterval(id + "-Early", null, transitionPoint,
         offsetBefore, Offset.Zero);
     LateInterval = new ZoneInterval(id + "-Late", transitionPoint, null,
         offsetAfter, Offset.Zero);
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:15,代码来源:SingleTransitionDateTimeZone.cs


示例6: ZoneTransition

 /// <summary>
 /// Initializes a new instance of the <see cref="ZoneTransition"/> class.
 /// </summary>
 /// <remarks>
 /// </remarks>
 /// <param name="instant">The instant that this transistion occurs at.</param>
 /// <param name="name">The name for the time at this transition e.g. PDT or PST.</param>
 /// <param name="standardOffset">The standard offset at this transition.</param>
 /// <param name="savings">The actual offset at this transition.</param>
 internal ZoneTransition(Instant instant, String name, Offset standardOffset, Offset savings)
 {
     Preconditions.CheckNotNull(name, "name");
     this.Instant = instant;
     this.Name = name;
     this.StandardOffset = standardOffset;
     this.Savings = savings;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:17,代码来源:ZoneTransition.cs


示例7: CountdownActor

        public CountdownActor(Label lbl, Form1 form, Instant deadline)
        {
            _labelUpdater = Context.ActorOf(Props.Create(() => new LabelUpdaterActor(lbl)));
            _alarm = Context.ActorOf(Props.Create(() => new AlarmActor(form)));
            _deadline = deadline;

            Receive<DateTime>(msg => UpdateDeadline(msg));
            Receive<object>(msg => Tick());
        }
开发者ID:GraanJonlo,项目名称:doomsday,代码行数:9,代码来源:CountdownActor.cs


示例8: AdditionWithDuration

 public void AdditionWithDuration()
 {
     // Some arbitrary instant. I've no idea when.
     Instant instant = new Instant(150000000);
     // A very short duration: a duration is simply a number of ticks.
     Duration duration = new Duration(1000);
     Instant later = instant + duration;
     Assert.AreEqual(new Instant(150001000), later);
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:InstantDemo.cs


示例9: Construction

 public void Construction()
 {
     // 10 million ticks = 1 second...
     Instant instant = new Instant(10000000);
     // Epoch is 1970 UTC
     // An instant isn't really "in" a time zone or calendar, but
     // it's convenient to consider UTC in the ISO-8601 calendar.
     Assert.AreEqual("1970-01-01T00:00:01Z", instant.ToString());
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:InstantDemo.cs


示例10: PartialZoneIntervalMap

 internal PartialZoneIntervalMap(Instant start, Instant end, IZoneIntervalMap map)
 {
     // Allowing empty maps makes life simpler.
     Preconditions.DebugCheckArgument(start <= end, nameof(end),
         "Invalid start/end combination: {0} - {1}", start, end);
     this.Start = start;
     this.End = end;
     this.map = map;
 }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:9,代码来源:PartialZoneIntervalMap.cs


示例11: Construct_EndOfTime_Truncated

 public void Construct_EndOfTime_Truncated()
 {
     const string name = "abc";
     var instant = new Instant(Instant.MaxValue.Ticks + minusOneHour.TotalTicks);
     var actual = new ZoneTransition(instant, name, threeHours, threeHours);
     Assert.AreEqual(instant, actual.Instant, "Instant");
     Assert.AreEqual(oneHour, actual.StandardOffset, "StandardOffset");
     Assert.AreEqual(Offset.Zero, actual.Savings, "Savings");
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:9,代码来源:ZoneTransitionTest.cs


示例12: GetZoneInterval

 /// <summary>
 /// Gets the zone interval for the given instant.
 /// </summary>
 /// <param name="instant">The Instant to test.</param>
 /// <returns>The ZoneInterval in effect at the given instant.</returns>
 /// <exception cref="ArgumentOutOfRangeException">The instant falls outside the bounds
 /// of the recurrence rules of the zone.</exception>
 public override ZoneInterval GetZoneInterval(Instant instant)
 {
     ZoneRecurrence recurrence;
     var next = NextTransition(instant, out recurrence);
     // Now we know the recurrence we're in, we can work out when we went into it. (We'll never have
     // two transitions into the same recurrence in a row.)
     Offset previousSavings = ReferenceEquals(recurrence, standardRecurrence) ? dstRecurrence.Savings : Offset.Zero;
     var previous = recurrence.PreviousOrSameOrFail(instant, standardOffset, previousSavings);
     return new ZoneInterval(recurrence.Name, previous.Instant, next.Instant, standardOffset + recurrence.Savings, recurrence.Savings);
 }
开发者ID:KonstantinDavidov,项目名称:nodatime,代码行数:17,代码来源:DaylightSavingsDateTimeZone.cs


示例13: Comparison

        public void Comparison()
        {
            Instant equal = new Instant(1, 100L);
            Instant greater1 = new Instant(1, 101L);
            Instant greater2 = new Instant(2, 0L);

            TestHelper.TestCompareToStruct(equal, equal, greater1);
            TestHelper.TestNonGenericCompareTo(equal, equal, greater1);
            TestHelper.TestOperatorComparisonEquality(equal, equal, greater1, greater2);
        }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:10,代码来源:InstantTest.Operators.cs


示例14: KeepAlive

        public Duration KeepAlive(Instant now)
        {
            var newTimestamp = now;
            var oldTimestamp = this.LastKeepAlive;

            this.LastKeepAlive = newTimestamp;

            var lag = newTimestamp - oldTimestamp;
            return lag;
        }
开发者ID:shoftee,项目名称:OpenStory,代码行数:10,代码来源:ActiveAccount.cs


示例15: SingleAggregateSchedule

 public void SingleAggregateSchedule()
 {
     Instant i = new Instant(Tester.RandomGenerator.RandomInt32());
     OneOffSchedule oneOffSchedule = new OneOffSchedule(i);
     AggregateSchedule aggregateSchedule = new AggregateSchedule(oneOffSchedule);
     Assert.AreEqual(1, aggregateSchedule.Count());
     Assert.AreEqual(i, aggregateSchedule.Next(i - TimeHelpers.OneSecond));
     Assert.AreEqual(i, aggregateSchedule.Next(i));
     Assert.AreEqual(Instant.MaxValue, aggregateSchedule.Next(i + Duration.FromTicks(1)));
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:10,代码来源:TestAggregateSchedule.cs


示例16: Max

 public void Max()
 {
     Instant x = new Instant(100);
     Instant y = new Instant(200);
     Assert.AreEqual(y, Instant.Max(x, y));
     Assert.AreEqual(y, Instant.Max(y, x));
     Assert.AreEqual(x, Instant.Max(x, Instant.MinValue));
     Assert.AreEqual(x, Instant.Max(Instant.MinValue, x));
     Assert.AreEqual(Instant.MaxValue, Instant.Max(Instant.MaxValue, x));
     Assert.AreEqual(Instant.MaxValue, Instant.Max(x, Instant.MaxValue));
 }
开发者ID:manirana007,项目名称:NodaTime,代码行数:11,代码来源:InstantTest.cs


示例17: Equality

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

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

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


示例18: TestInstantOperators

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

            var time1 = new Instant(TestTime1);
            var time2 = new Instant(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,代码来源:InstantTest.cs


示例19: ScheduledActionResult

 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledActionResult"/> class.
 /// </summary>
 /// <param name="due">The due.</param>
 /// <param name="started">The started.</param>
 /// <param name="duration">The duration.</param>
 /// <param name="exception">The exception.</param>
 /// <param name="cancelled">if set to <see langword="true"/> the action was cancelled.</param>
 /// <remarks></remarks>
 protected ScheduledActionResult(
     Instant due,
     Instant started,
     Duration duration,
     [CanBeNull] Exception exception,
     bool cancelled)
 {
     Due = due;
     Started = started;
     Duration = duration;
     Exception = exception;
     Cancelled = cancelled;
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:22,代码来源:ScheduledActionResult.cs


示例20: TestToStringBase

        private static void TestToStringBase(Instant value, string gvalue)
        {
            string actual = value.ToString();
            Assert.AreEqual(gvalue, actual);
            actual = value.ToString("g", null);
            Assert.AreEqual(gvalue, actual);
            actual = value.ToString("g", CultureInfo.InvariantCulture);
            Assert.AreEqual(gvalue, actual);

            actual = string.Format("{0}", value);
            Assert.AreEqual(gvalue, actual);
            actual = string.Format("{0:g}", value);
            Assert.AreEqual(gvalue, actual);
        }
开发者ID:nicklbailey,项目名称:nodatime,代码行数:14,代码来源:InstantTest.Format.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Instruction类代码示例发布时间:2022-05-24
下一篇:
C# InstanceReference类代码示例发布时间: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