示例#1
0
        /// <summary>
        /// Finds the offset info for a local date-time and transition.
        /// </summary>
        /// <param name="dt">  the date-time, not null </param>
        /// <param name="trans">  the transition, not null </param>
        /// <returns> the offset info, not null </returns>
        private Object FindOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans)
        {
            LocalDateTime localTransition = trans.DateTimeBefore;

            if (trans.Gap)
            {
                if (dt.IsBefore(localTransition))
                {
                    return(trans.OffsetBefore);
                }
                if (dt.IsBefore(trans.DateTimeAfter))
                {
                    return(trans);
                }
                else
                {
                    return(trans.OffsetAfter);
                }
            }
            else
            {
                if (dt.IsBefore(localTransition) == false)
                {
                    return(trans.OffsetAfter);
                }
                if (dt.IsBefore(trans.DateTimeAfter))
                {
                    return(trans.OffsetBefore);
                }
                else
                {
                    return(trans);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="standardTransitions">  the standard transitions, not null </param>
        /// <param name="standardOffsets">  the standard offsets, not null </param>
        /// <param name="savingsInstantTransitions">  the standard transitions, not null </param>
        /// <param name="wallOffsets">  the wall offsets, not null </param>
        /// <param name="lastRules">  the recurring last rules, size 15 or less, not null </param>
        private ZoneRules(long[] standardTransitions, ZoneOffset[] standardOffsets, long[] savingsInstantTransitions, ZoneOffset[] wallOffsets, ZoneOffsetTransitionRule[] lastRules) : base()
        {
            this.StandardTransitions       = standardTransitions;
            this.StandardOffsets           = standardOffsets;
            this.SavingsInstantTransitions = savingsInstantTransitions;
            this.WallOffsets = wallOffsets;
            this.LastRules   = lastRules;

            if (savingsInstantTransitions.Length == 0)
            {
                this.SavingsLocalTransitions = EMPTY_LDT_ARRAY;
            }
            else
            {
                // convert savings transitions to locals
                IList <LocalDateTime> localTransitionList = new List <LocalDateTime>();
                for (int i = 0; i < savingsInstantTransitions.Length; i++)
                {
                    ZoneOffset           before = wallOffsets[i];
                    ZoneOffset           after  = wallOffsets[i + 1];
                    ZoneOffsetTransition trans  = new ZoneOffsetTransition(savingsInstantTransitions[i], before, after);
                    if (trans.Gap)
                    {
                        localTransitionList.Add(trans.DateTimeBefore);
                        localTransitionList.Add(trans.DateTimeAfter);
                    }
                    else
                    {
                        localTransitionList.Add(trans.DateTimeAfter);
                        localTransitionList.Add(trans.DateTimeBefore);
                    }
                }
                this.SavingsLocalTransitions = localTransitionList.ToArray();
            }
        }
示例#3
0
        /// <summary>
        /// Gets the offset applicable at the specified instant in these rules.
        /// <para>
        /// The mapping from an instant to an offset is simple, there is only
        /// one valid offset for each instant.
        /// This method returns that offset.
        ///
        /// </para>
        /// </summary>
        /// <param name="instant">  the instant to find the offset for, not null, but null
        ///  may be ignored if the rules have a single offset for all instants </param>
        /// <returns> the offset, not null </returns>
        public ZoneOffset GetOffset(Instant instant)
        {
            if (SavingsInstantTransitions.Length == 0)
            {
                return(StandardOffsets[0]);
            }
            long epochSec = instant.EpochSecond;

            // check if using last rules
            if (LastRules.Length > 0 && epochSec > SavingsInstantTransitions[SavingsInstantTransitions.Length - 1])
            {
                int year = FindYear(epochSec, WallOffsets[WallOffsets.Length - 1]);
                ZoneOffsetTransition[] transArray = FindTransitionArray(year);
                ZoneOffsetTransition   trans      = null;
                for (int i = 0; i < transArray.Length; i++)
                {
                    trans = transArray[i];
                    if (epochSec < trans.ToEpochSecond())
                    {
                        return(trans.OffsetBefore);
                    }
                }
                return(trans.OffsetAfter);
            }

            // using historic rules
            int index = Arrays.BinarySearch(SavingsInstantTransitions, epochSec);

            if (index < 0)
            {
                // switch negative insert position to start of matched range
                index = -index - 2;
            }
            return(WallOffsets[index + 1]);
        }
示例#4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private static Object readInternal(byte type, java.io.DataInput in) throws java.io.IOException, ClassNotFoundException
        private static Object ReadInternal(sbyte type, DataInput @in)
        {
            switch (type)
            {
            case ZRULES:
                return(ZoneRules.ReadExternal(@in));

            case ZOT:
                return(ZoneOffsetTransition.ReadExternal(@in));

            case ZOTRULE:
                return(ZoneOffsetTransitionRule.ReadExternal(@in));

            default:
                throw new StreamCorruptedException("Unknown serialized type");
            }
        }
示例#5
0
        /// <summary>
        /// Finds the appropriate transition array for the given year.
        /// </summary>
        /// <param name="year">  the year, not null </param>
        /// <returns> the transition array, not null </returns>
        private ZoneOffsetTransition[] FindTransitionArray(int year)
        {
            Integer yearObj = year;             // should use Year class, but this saves a class load

            ZoneOffsetTransition[] transArray = LastRulesCache[yearObj];
            if (transArray != null)
            {
                return(transArray);
            }
            ZoneOffsetTransitionRule[] ruleArray = LastRules;
            transArray = new ZoneOffsetTransition[ruleArray.Length];
            for (int i = 0; i < ruleArray.Length; i++)
            {
                transArray[i] = ruleArray[i].CreateTransition(year);
            }
            if (year < LAST_CACHED_YEAR)
            {
                LastRulesCache.PutIfAbsent(yearObj, transArray);
            }
            return(transArray);
        }