本文整理汇总了C#中NodaTime.DateTimeZone.GetZoneIntervals方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeZone.GetZoneIntervals方法的具体用法?C# DateTimeZone.GetZoneIntervals怎么用?C# DateTimeZone.GetZoneIntervals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodaTime.DateTimeZone
的用法示例。
在下文中一共展示了DateTimeZone.GetZoneIntervals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimeZoneOffsetProvider
/// <summary>
/// Initializes a new instance of the <see cref="TimeZoneOffsetProvider"/> class
/// </summary>
/// <param name="timeZone">The time zone to provide offsets for</param>
/// <param name="utcStartTime">The start of the range of offsets</param>
/// <param name="utcEndTime">The en of the range of offsets</param>
public TimeZoneOffsetProvider(DateTimeZone timeZone, DateTime utcStartTime, DateTime utcEndTime)
{
_timeZone = timeZone;
// pad the end so we get the correct zone interval
utcEndTime += TimeSpan.FromDays(2*365);
var start = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcStartTime));
var end = DateTimeZone.Utc.AtLeniently(LocalDateTime.FromDateTime(utcEndTime));
var zoneIntervals = _timeZone.GetZoneIntervals(start.ToInstant(), end.ToInstant());
_discontinuities = new Queue<long>(zoneIntervals.Select(x => x.Start.ToDateTimeUtc().Ticks));
if (_discontinuities.Count == 0)
{
// end of discontinuities
_nextDiscontinuity = DateTime.MaxValue.Ticks;
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(DateTime.UtcNow)).Ticks;
}
else
{
// get the offset just before the next discontinuity to initialize
_nextDiscontinuity = _discontinuities.Dequeue();
_currentOffsetTicks = _timeZone.GetUtcOffset(Instant.FromDateTimeUtc(new DateTime(_nextDiscontinuity - 1, DateTimeKind.Utc))).Ticks;
}
}
示例2: DumpZone
private static void DumpZone(DateTimeZone zone, Options options)
{
Console.Write("{0}\r\n", zone.Id);
var initial = zone.GetZoneInterval(Instant.MinValue);
Console.Write("Initially: {0} {1} {2}\r\n",
OffsetPattern.Format(initial.WallOffset),
initial.Savings != Offset.Zero ? "daylight" : "standard",
initial.Name);
foreach (var zoneInterval in zone.GetZoneIntervals(options.Start, options.End)
.Where(zi => zi.HasStart && zi.Start >= options.Start))
{
Console.Write("{0} {1} {2} {3}\r\n",
InstantPattern.Format(zoneInterval.Start),
OffsetPattern.Format(zoneInterval.WallOffset),
zoneInterval.Savings != Offset.Zero ? "daylight" : "standard",
zoneInterval.Name);
}
}