本文整理汇总了C#中Instant.ToUnixTimeTicks方法的典型用法代码示例。如果您正苦于以下问题:C# Instant.ToUnixTimeTicks方法的具体用法?C# Instant.ToUnixTimeTicks怎么用?C# Instant.ToUnixTimeTicks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Instant
的用法示例。
在下文中一共展示了Instant.ToUnixTimeTicks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteZoneIntervalTransition
public void WriteZoneIntervalTransition(Instant? previous, Instant value)
{
if (previous != null)
{
Preconditions.CheckArgument(value >= previous.Value, nameof(value), "Transition must move forward in time");
}
unchecked
{
if (value == Instant.BeforeMinValue)
{
WriteCount(ZoneIntervalConstants.MarkerMinValue);
return;
}
if (value == Instant.AfterMaxValue)
{
WriteCount(ZoneIntervalConstants.MarkerMaxValue);
return;
}
// In practice, most zone interval transitions will occur within 4000-6000 hours of the previous one
// (i.e. about 5-8 months), and at an integral number of hours difference. We therefore gain a
// significant reduction in output size by encoding transitions as the whole number of hours since the
// previous, if possible.
// If the previous value was "the start of time" then there's no point in trying to use it.
if (previous != null && previous.Value != Instant.BeforeMinValue)
{
// Note that the difference might exceed the range of a long, so we can't use a Duration here.
ulong ticks = (ulong) (value.ToUnixTimeTicks() - previous.Value.ToUnixTimeTicks());
if (ticks % TicksPerHour == 0)
{
ulong hours = ticks / TicksPerHour;
// As noted above, this will generally fall within the 4000-6000 range, although values up to
// ~700,000 exist in TZDB.
if (ZoneIntervalConstants.MinValueForHoursSincePrevious <= hours &&
hours < ZoneIntervalConstants.MinValueForMinutesSinceEpoch)
{
WriteCount((int) hours);
return;
}
}
}
// We can't write the transition out relative to the previous transition, so let's next try writing it
// out as a whole number of minutes since an (arbitrary, known) epoch.
if (value >= ZoneIntervalConstants.EpochForMinutesSinceEpoch)
{
ulong ticks = (ulong) (value.ToUnixTimeTicks() - ZoneIntervalConstants.EpochForMinutesSinceEpoch.ToUnixTimeTicks());
if (ticks % TicksPerMinute == 0)
{
ulong minutes = ticks / TicksPerMinute;
// We typically have a count on the order of 80M here.
if (ZoneIntervalConstants.MinValueForMinutesSinceEpoch < minutes && minutes <= int.MaxValue)
{
WriteCount((int) minutes);
return;
}
}
}
// Otherwise, just write out a marker followed by the instant as a 64-bit number of ticks. Note that
// while most of the values we write here are actually whole numbers of _seconds_, optimising for that
// case will save around 2KB (with tzdb 2012j), so doesn't seem worthwhile.
WriteCount(ZoneIntervalConstants.MarkerRaw);
WriteInt64(value.ToUnixTimeTicks());
}
}