本文整理汇总了C#中Instant类的典型用法代码示例。如果您正苦于以下问题:C# Instant类的具体用法?C# Instant怎么用?C# Instant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instant类属于命名空间,在下文中一共展示了Instant类的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());
}
示例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));
}
示例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}");
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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());
}
示例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;
}
示例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");
}
示例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);
}
示例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);
}
示例14: KeepAlive
public Duration KeepAlive(Instant now)
{
var newTimestamp = now;
var oldTimestamp = this.LastKeepAlive;
this.LastKeepAlive = newTimestamp;
var lag = newTimestamp - oldTimestamp;
return lag;
}
示例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)));
}