Ejemplo n.º 1
0
        /// <summary>
        /// Get history of offsets with keys as zoned time. Used to convert from zoned to UTC time.
        /// </summary>
        /// <returns></returns>
        public static SortedMap <DateTime, long> GetOffsetsFromZoned(string tzFrom, bool standardOffsetOnly = false)
        {
            string tz;

            if (!Normalizer.TryGetValue(tzFrom.ToLowerInvariant(), out tz))
            {
                tz = tzFrom;
            }
            var sortedMap = new SortedMap <DateTime, long>();

            if (tz.ToLowerInvariant() == "utc")
            {
                sortedMap.Set(new DateTime(0L, DateTimeKind.Unspecified), 0);
            }
            else
            {
                var givenTz   = DateTimeZoneProviders.Tzdb[tz];
                var intervals = givenTz.GetZoneIntervals(Instant.FromDateTimeUtc(
                                                             // https://en.wikipedia.org/wiki/International_Meridian_Conference
                                                             new DateTime(1884, 10, 22, 12, 0, 0, DateTimeKind.Utc)
                                                             ), Instant.MaxValue);
                foreach (var interval in intervals)
                {
                    var localStart  = interval.IsoLocalStart.ToDateTimeUnspecified();
                    var offset      = standardOffsetOnly ? interval.StandardOffset : interval.WallOffset;
                    var offsetTicks = offset.Ticks;
                    sortedMap.TryAddLast(localStart, offsetTicks);
                }
            }
            sortedMap.Complete();
            return(sortedMap);
        }
Ejemplo n.º 2
0
        public ContractsTests(ISeries <K, V> testSeries,
                              SortedMap <K, V> materializedSeries,
                              SortedMap <K, V> ephemeralSeries = null)
        {
            _testSeries         = testSeries ?? throw new ArgumentNullException(nameof(testSeries));
            _materializedSeries = materializedSeries ?? throw new ArgumentNullException(nameof(materializedSeries));
            _ephemeralSeries    = ephemeralSeries;

            if (!ReferenceEquals(null, ephemeralSeries))
            {
                var eqc = EqualityComparer <V> .Default;
                // TODO (UX) Spreads signature conflicts with LINQ, easy to fix but not very convenient
                var intersect = materializedSeries.Zip(ephemeralSeries, (l, r) =>
                {
                    if (!eqc.Equals(l, r))
                    {
                        throw new ArgumentException("materializedSeries and ephemeralSeries contain different values for the same keys");
                    }
                    else
                    {
                        return(l);
                    }
                });
                if (intersect.First.IsMissing)
                {
                    foreach (var kvp in materializedSeries.Take(10))
                    {
                        ephemeralSeries.Set(kvp.Key, kvp.Value);
                    }
                }
            }
        }