本文整理汇总了C#中NodaTime.DateTimeZone类的典型用法代码示例。如果您正苦于以下问题:C# DateTimeZone类的具体用法?C# DateTimeZone怎么用?C# DateTimeZone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeZone类属于NodaTime命名空间,在下文中一共展示了DateTimeZone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddTimeZone
/// <summary>
/// Adds the specified time zone to this time keeper
/// </summary>
/// <param name="timeZone"></param>
public void AddTimeZone(DateTimeZone timeZone)
{
if (!_localTimeKeepers.ContainsKey(timeZone))
{
_localTimeKeepers[timeZone] = new LocalTimeKeeper(_utcDateTime, timeZone);
}
}
示例2: 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;
}
}
示例3: GetCoarseFundamentals
/// <summary>
/// Gets the <see cref="CoarseFundamental"/> data for the specified market/date
/// </summary>
public static IEnumerable<CoarseFundamental> GetCoarseFundamentals(string market, DateTimeZone timeZone, DateTime date, bool isLiveMode)
{
var factory = new CoarseFundamental();
var config = new SubscriptionDataConfig(typeof(CoarseFundamental), SecurityType.Equity, new Symbol(market + "-coarse"), Resolution.Daily, market, timeZone, true, false, true, false);
var reader = new BaseDataSubscriptionFactory(config, date, isLiveMode);
var source = factory.GetSource(config, date, isLiveMode);
return reader.Read(source).OfType<CoarseFundamental>();
}
示例4: AlwaysOpen
/// <summary>
/// Gets a <see cref="SecurityExchangeHours"/> instance that is always open
/// </summary>
public static SecurityExchangeHours AlwaysOpen(DateTimeZone timeZone)
{
var dayOfWeeks = Enum.GetValues(typeof (DayOfWeek)).OfType<DayOfWeek>();
return new SecurityExchangeHours(timeZone,
Enumerable.Empty<DateTime>(),
dayOfWeeks.Select(LocalMarketHours.OpenAllDay).ToDictionary(x => x.DayOfWeek)
);
}
示例5: ScheduleManager
/// <summary>
/// Initializes a new instance of the <see cref="ScheduleManager"/> class
/// </summary>
/// <param name="securities">Securities manager containing the algorithm's securities</param>
/// <param name="timeZone">The algorithm's time zone</param>
public ScheduleManager(SecurityManager securities, DateTimeZone timeZone)
{
_securities = securities;
DateRules = new DateRules(securities);
TimeRules = new TimeRules(securities, timeZone);
// used for storing any events before the event schedule is set
_preInitializedEvents = new List<ScheduledEvent>();
}
示例6: AmbiguousTimeException
/// <summary>
/// Constructs an instance from the given information.
/// </summary>
/// <remarks>
/// User code is unlikely to need to deliberately call this constructor except
/// possibly for testing.
/// </remarks>
/// <param name="localDateTime">The local date and time that was ambiguous</param>
/// <param name="zone">The time zone in which the mapping is ambiguous</param>
/// <param name="earlierMapping">The earlier possible mapping</param>
/// <param name="laterMapping">The later possible mapping</param>
public AmbiguousTimeException(LocalDateTime localDateTime, DateTimeZone zone,
ZonedDateTime earlierMapping,
ZonedDateTime laterMapping)
: base("Local time " + localDateTime + " is ambiguous in time zone " + zone.Id)
{
this.localDateTime = localDateTime;
this.zone = zone;
this.earlierMapping = earlierMapping;
this.laterMapping = laterMapping;
}
示例7: Add
/// <summary>
/// Add Market Data Required (Overloaded method for backwards compatibility).
/// </summary>
/// <param name="symbol">Symbol of the asset we're like</param>
/// <param name="resolution">Resolution of Asset Required</param>
/// <param name="timeZone">The time zone the subscription's data is time stamped in</param>
/// <param name="exchangeTimeZone">Specifies the time zone of the exchange for the security this subscription is for. This
/// is this output time zone, that is, the time zone that will be used on BaseData instances</param>
/// <param name="isCustomData">True if this is custom user supplied data, false for normal QC data</param>
/// <param name="fillDataForward">when there is no data pass the last tradebar forward</param>
/// <param name="extendedMarketHours">Request premarket data as well when true </param>
/// <returns>The newly created <see cref="SubscriptionDataConfig"/></returns>
public SubscriptionDataConfig Add(Symbol symbol, Resolution resolution, DateTimeZone timeZone, DateTimeZone exchangeTimeZone, bool isCustomData = false, bool fillDataForward = true, bool extendedMarketHours = false)
{
//Set the type: market data only comes in two forms -- ticks(trade by trade) or tradebar(time summaries)
var dataType = typeof(TradeBar);
if (resolution == Resolution.Tick)
{
dataType = typeof(Tick);
}
return Add(dataType, symbol, resolution, timeZone, exchangeTimeZone, isCustomData, fillDataForward, extendedMarketHours, false);
}
示例8: ToBaseData
public RestApiBaseData ToBaseData(DateTimeZone timeZone, TimeSpan period)
{
var dateTime = QuantConnect.Time.UnixTimeStampToDateTime(time).ConvertFromUtc(timeZone).Subtract(period);
return new RestApiBaseData
{
Symbol = symbol,
Time = dateTime,
EndTime = dateTime.Add(period),
Value = (decimal) alpha
};
}
示例9: GetHistory
/// <summary>
/// Gets the history for the requested securities
/// </summary>
/// <param name="requests">The historical data requests</param>
/// <param name="sliceTimeZone">The time zone used when time stamping the slice instances</param>
/// <returns>An enumerable of the slices of data covering the span specified in each request</returns>
public IEnumerable<Slice> GetHistory(IEnumerable<HistoryRequest> requests, DateTimeZone sliceTimeZone)
{
foreach (var request in requests)
{
var granularity = ToGranularity(request.Resolution);
// Oanda only has 5-second bars, we return these for Resolution.Second
var period = request.Resolution == Resolution.Second ?
TimeSpan.FromSeconds(5) : request.Resolution.ToTimeSpan();
// set the starting date/time
var startDateTime = request.StartTimeUtc;
// loop until last date
while (startDateTime <= request.EndTimeUtc)
{
var start = startDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
// request blocks of bars at the requested resolution with a starting date/time
var oandaSymbol = _symbolMapper.GetBrokerageSymbol(request.Symbol);
var candles = DownloadBars(oandaSymbol, start, MaxBarsPerRequest, granularity);
if (candles.Count == 0)
break;
foreach (var candle in candles)
{
var time = GetDateTimeFromString(candle.time);
if (time > request.EndTimeUtc)
break;
var tradeBar = new TradeBar(
time,
request.Symbol,
Convert.ToDecimal(candle.openMid),
Convert.ToDecimal(candle.highMid),
Convert.ToDecimal(candle.lowMid),
Convert.ToDecimal(candle.closeMid),
0,
period);
DataPointCount++;
yield return new Slice(tradeBar.EndTime, new[] { tradeBar });
}
// calculate the next request datetime
startDateTime = GetDateTimeFromString(candles[candles.Count - 1].time).Add(period);
}
}
}
示例10: PullTests
public PullTests()
{
timeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
store = new FakeStore();
storeFactory = new TestStoreFactory(store);
Emit(NewId<LocalCalendar>(),
new RemoteCalendarAdded(
new FakeRemote
{
Id = NewId<RemoteCalendar>()
}));
}
示例11: SecurityExchangeHours
/// <summary>
/// Initializes a new instance of the <see cref="SecurityExchangeHours"/> class
/// </summary>
/// <param name="timeZone">The time zone the dates and hours are represented in</param>
/// <param name="holidayDates">The dates this exchange is closed for holiday</param>
/// <param name="marketHoursForEachDayOfWeek">The exchange's schedule for each day of the week</param>
public SecurityExchangeHours(DateTimeZone timeZone, IEnumerable<DateTime> holidayDates, IReadOnlyDictionary<DayOfWeek, LocalMarketHours> marketHoursForEachDayOfWeek)
{
_timeZone = timeZone;
_holidays = holidayDates.Select(x => x.Date.Ticks).ToHashSet();
// make a copy of the dictionary for internal use
_openHoursByDay = new Dictionary<DayOfWeek, LocalMarketHours>(marketHoursForEachDayOfWeek.ToDictionary());
SetMarketHoursForDay(DayOfWeek.Sunday, out _sunday);
SetMarketHoursForDay(DayOfWeek.Monday, out _monday);
SetMarketHoursForDay(DayOfWeek.Tuesday, out _tuesday);
SetMarketHoursForDay(DayOfWeek.Wednesday, out _wednesday);
SetMarketHoursForDay(DayOfWeek.Thursday, out _thursday);
SetMarketHoursForDay(DayOfWeek.Friday, out _friday);
SetMarketHoursForDay(DayOfWeek.Saturday, out _saturday);
}
示例12: 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);
}
}
示例13: At
/// <summary>
/// Specifies an event should fire at the specified time of day in the specified time zone
/// </summary>
/// <param name="hour">The hour</param>
/// <param name="minute">The minute</param>
/// <param name="second">The second</param>
/// <param name="timeZone">The time zone the event time is represented in</param>
/// <returns>A time rule that fires at the specified time in the algorithm's time zone</returns>
public ITimeRule At(int hour, int minute, int second, DateTimeZone timeZone)
{
return At(new TimeSpan(hour, minute, second), timeZone);
}
示例14: SubscriptionDataConfig
/// <summary>
/// Copy constructor with overrides
/// </summary>
/// <param name="config">The config to copy, then overrides are applied and all option</param>
/// <param name="objectType">Type of the data objects.</param>
/// <param name="securityType">SecurityType Enum Set Equity/FOREX/Futures etc.</param>
/// <param name="symbol">Symbol of the asset we're requesting</param>
/// <param name="resolution">Resolution of the asset we're requesting</param>
/// <param name="market">The market this subscription comes from</param>
/// <param name="timeZone">The time zone the raw data is time stamped in</param>
/// <param name="fillForward">Fill in gaps with historical data</param>
/// <param name="extendedHours">Equities only - send in data from 4am - 8pm</param>
/// <param name="isInternalFeed">Set to true if this subscription is added for the sole purpose of providing currency conversion rates,
/// setting this flag to true will prevent the data from being sent into the algorithm's OnData methods</param>
/// <param name="isCustom">True if this is user supplied custom data, false for normal QC data</param>
public SubscriptionDataConfig(SubscriptionDataConfig config,
Type objectType = null,
SecurityType? securityType = null,
Symbol symbol = null,
Resolution? resolution = null,
string market = null,
DateTimeZone timeZone = null,
bool? fillForward = null,
bool? extendedHours = null,
bool? isInternalFeed = null,
bool? isCustom = null)
: this(objectType ?? config.Type,
symbol ?? config.Symbol,
resolution ?? config.Resolution,
timeZone ?? config.TimeZone,
fillForward ?? config.FillDataForward,
extendedHours ?? config.ExtendedMarketHours,
isInternalFeed ?? config.IsInternalFeed,
isCustom ?? config.IsCustomData)
{
}
示例15: SetDefaultTimeZone
/// <summary>
/// Sets the default time zone
/// </summary>
/// <param name="timeZone">The time zone to use for helper methods that can't resolve a time zone</param>
public void SetDefaultTimeZone(DateTimeZone timeZone)
{
_timeZone = timeZone;
}