Ejemplo n.º 1
0
        public Option GetOption(Symbol symbol, Equity underlying, NodaTime.DateTimeZone tz)
        {
            var option = new Option(
                SecurityExchangeHours.AlwaysOpen(tz),
                new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, tz, tz, true, false, false),
                new Cash(Currencies.USD, 0, 1m),
                new OptionSymbolProperties(SymbolProperties.GetDefault(Currencies.USD)),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null
                );

            option.Underlying = underlying;

            return(option);
        }
        /// <summary>
        /// Convert IANA timezone to a UTC offset.
        /// </summary>
        /// <param name="IanaTimezone">eg "America/Vancouver"</param>
        /// <returns>The offset eg -7</returns>
        public static Int16 GetUtcOffset(String IanaTimezone)
        {
            Int16 utcOffset = 0;

            try {
                NodaTime.IDateTimeZoneProvider tzProvider = NodaTime.DateTimeZoneProviders.Tzdb;
                if (!tzProvider.Ids.Contains(IanaTimezone))
                {
                    log.Warn("Could not map IANA timezone '" + IanaTimezone + "' to UTC offset.");
                }
                else
                {
                    NodaTime.DateTimeZone tz     = tzProvider[IanaTimezone];
                    NodaTime.Offset       offset = tz.GetUtcOffset(new NodaTime.Instant());
                    utcOffset = Convert.ToInt16(offset.Seconds / 3600);
                }
            } catch (System.Exception ex) {
                OGCSexception.Analyse("Not able to convert IANA timezone '" + IanaTimezone + "' to UTC offset.", ex);
            }
            return(utcOffset);
        }
        public TaskItemWrapper Map2To1(ITodo source, TaskItemWrapper target, IEntityMappingLogger logger)
        {
            target.Inner.Subject = source.Summary;

            target.Inner.Body = _configuration.MapBody ? source.Description : string.Empty;

            NodaTime.DateTimeZone localZone = NodaTime.DateTimeZoneProviders.Bcl.GetSystemDefault();

            if (source.Start != null)
            {
                if (source.Start.IsUniversalTime)
                {
                    target.Inner.StartDate = NodaTime.Instant.FromDateTimeUtc(source.Start.Value).InZone(localZone).ToDateTimeUnspecified().Date;
                }
                else
                {
                    target.Inner.StartDate = source.Start.Date;
                }
            }

            if (source.Due != null)
            {
                if (source.Start == null || source.Start.Value <= source.Due.Value)
                {
                    if (source.Due.IsUniversalTime)
                    {
                        target.Inner.DueDate = NodaTime.Instant.FromDateTimeUtc(source.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date;
                    }
                    else
                    {
                        target.Inner.DueDate = source.Due.Date;
                    }
                }
            }
            if (source.Completed != null)
            {
                if (source.Completed.IsUniversalTime)
                {
                    target.Inner.DateCompleted = NodaTime.Instant.FromDateTimeUtc(source.Completed.Value).InZone(localZone).ToDateTimeUnspecified().Date;
                }
                else
                {
                    target.Inner.DateCompleted = source.Completed.Date;
                }
                target.Inner.Complete = true;
            }
            else
            {
                target.Inner.Complete = false;
            }

            target.Inner.PercentComplete = source.PercentComplete;

            if (_configuration.MapPriority)
            {
                target.Inner.Importance = CommonEntityMapper.MapPriority2To1(source.Priority);
            }

            target.Inner.Sensitivity = CommonEntityMapper.MapPrivacy2To1(source.Class, false);

            target.Inner.Status = MapStatus2To1(source.Status);

            MapCategories2To1(source, target);

            MapReminder2To1(source, target, logger);

            if (_configuration.MapRecurringTasks)
            {
                MapRecurrance2To1(source, target, logger);
            }

            return(target);
        }
Ejemplo n.º 4
0
        protected override bool AreEqual(TaskEntityMatchData atypeEntity, IICalendar btypeEntity)
        {
            var task = btypeEntity.Todos[0];

            if (atypeEntity.Subject == task.Summary)
            {
                NodaTime.DateTimeZone localZone = NodaTime.DateTimeZoneProviders.Bcl.GetSystemDefault();
                DateTime dateNull = new DateTime(4501, 1, 1, 0, 0, 0);

                if (task.Start != null)
                {
                    if (task.Start.IsUniversalTime)
                    {
                        if (atypeEntity.StartDate == NodaTime.Instant.FromDateTimeUtc(task.Start.Value).InZone(localZone).ToDateTimeUnspecified().Date)
                        {
                            if (task.Due != null)
                            {
                                if (task.Due.IsUniversalTime)
                                {
                                    return(atypeEntity.DueDate == NodaTime.Instant.FromDateTimeUtc(task.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date);
                                }
                                else
                                {
                                    return(atypeEntity.DueDate == task.Due.Date);
                                }
                            }
                            return(atypeEntity.DueDate == dateNull);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (atypeEntity.StartDate == task.Start.Date)
                        {
                            if (task.Due != null)
                            {
                                if (task.Due.IsUniversalTime)
                                {
                                    return(atypeEntity.DueDate == NodaTime.Instant.FromDateTimeUtc(task.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date);
                                }
                                else
                                {
                                    return(atypeEntity.DueDate == task.Due.Date);
                                }
                            }
                            return(atypeEntity.DueDate == dateNull);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                else if (task.Due != null)
                {
                    if (task.Due.IsUniversalTime)
                    {
                        return(atypeEntity.StartDate == dateNull && atypeEntity.DueDate == NodaTime.Instant.FromDateTimeUtc(task.Due.Value).InZone(localZone).ToDateTimeUnspecified().Date);
                    }
                    else
                    {
                        return(atypeEntity.StartDate == dateNull && atypeEntity.DueDate == task.Due.Date);
                    }
                }
                else
                {
                    return(atypeEntity.StartDate == dateNull && atypeEntity.DueDate == dateNull);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        private Equity GetEquity(Symbol symbol, decimal underlyingPrice, decimal underlyingVol, NodaTime.DateTimeZone tz)
        {
            var equity = new Equity(
                SecurityExchangeHours.AlwaysOpen(tz),
                new SubscriptionDataConfig(typeof(TradeBar), symbol, Resolution.Minute, tz, tz, true, false, false),
                new Cash(Currencies.USD, 0, 1m),
                SymbolProperties.GetDefault(Currencies.USD),
                ErrorCurrencyConverter.Instance,
                RegisteredSecurityDataTypesProvider.Null
                );

            equity.SetMarketPrice(new Tick {
                Value = underlyingPrice
            });
            equity.VolatilityModel = new DummyVolatilityModel(underlyingVol);

            return(equity);
        }