Exemplo n.º 1
0
        /// <summary>
        /// Checks if the time zone has equivalent transitions in the time range.
        /// This method returns true when all of transition times, from/to standard
        /// offsets and DST savings used by this time zone match the other in the
        /// time range.
        /// </summary>
        ///
        /// <param name="tz">The instance of <c>TimeZone</c></param>
        /// <param name="start">The start time of the evaluated time range (inclusive)</param>
        /// <param name="end">The end time of the evaluated time range (inclusive)</param>
        /// <param name="ignoreDstAmount">When true, any transitions with only daylight saving amountchanges will be ignored, except either of them is zero. Forexample, a transition from rawoffset 3:00/dstsavings 1:00 torawoffset 2:00/dstsavings 2:00 is excluded from thecomparison, but a transtion from rawoffset 2:00/dstsavings1:00 to rawoffset 3:00/dstsavings 0:00 is included.</param>
        /// <returns>true if the other time zone has the equivalent transitions in the
        /// time range. When tz is not a <c>BasicTimeZone</c>, this
        /// method returns false.</returns>
        /// @draft ICU 3.8
        /// @provisional This API might change or be removed in a future release.
        public bool HasEquivalentTransitions(TimeZone tz, long start, long end,
                                             bool ignoreDstAmount)
        {
            if (HasSameRules(tz))
            {
                return(true);
            }
            if (!(tz  is  BasicTimeZone))
            {
                return(false);
            }

            // Check the offsets at the start time
            int[] offsets1 = new int[2];
            int[] offsets2 = new int[2];

            GetOffset(start, false, offsets1);
            tz.GetOffset(start, false, offsets2);

            if (ignoreDstAmount)
            {
                if ((offsets1[0] + offsets1[1] != offsets2[0] + offsets2[1]) ||
                    (offsets1[1] != 0 && offsets2[1] == 0) ||
                    (offsets1[1] == 0 && offsets2[1] != 0))
                {
                    return(false);
                }
            }
            else
            {
                if (offsets1[0] != offsets2[0] || offsets1[1] != offsets2[1])
                {
                    return(false);
                }
            }

            // Check transitions in the range
            long time = start;

            while (true)
            {
                TimeZoneTransition tr1 = GetNextTransition(time, false);
                TimeZoneTransition tr2 = ((BasicTimeZone)tz).GetNextTransition(
                    time, false);

                if (ignoreDstAmount)
                {
                    // Skip a transition which only differ the amount of DST savings
                    if (tr1 != null &&
                        (tr1.GetFrom().GetRawOffset()
                         + tr1.GetFrom().GetDSTSavings() == tr1.GetTo()
                         .GetRawOffset() + tr1.GetTo().GetDSTSavings()) &&
                        (tr1.GetFrom().GetDSTSavings() != 0 && tr1.GetTo()
                         .GetDSTSavings() != 0))
                    {
                        tr1 = GetNextTransition(tr1.GetTime(), false);
                    }
                    if (tr2 != null &&
                        (tr2.GetFrom().GetRawOffset()
                         + tr2.GetFrom().GetDSTSavings() == tr2.GetTo()
                         .GetRawOffset() + tr2.GetTo().GetDSTSavings()) &&
                        (tr2.GetFrom().GetDSTSavings() != 0 && tr2.GetTo()
                         .GetDSTSavings() != 0))
                    {
                        tr2 = GetNextTransition(tr2.GetTime(), false);
                    }
                }

                bool inRange1 = false;
                bool inRange2 = false;
                if (tr1 != null)
                {
                    if (tr1.GetTime() <= end)
                    {
                        inRange1 = true;
                    }
                }
                if (tr2 != null)
                {
                    if (tr2.GetTime() <= end)
                    {
                        inRange2 = true;
                    }
                }
                if (!inRange1 && !inRange2)
                {
                    // No more transition in the range
                    break;
                }
                if (!inRange1 || !inRange2)
                {
                    return(false);
                }
                if (tr1.GetTime() != tr2.GetTime())
                {
                    return(false);
                }
                if (ignoreDstAmount)
                {
                    if (tr1.GetTo().GetRawOffset() + tr1.GetTo().GetDSTSavings() != tr2
                        .GetTo().GetRawOffset() + tr2.GetTo().GetDSTSavings() ||
                        tr1.GetTo().GetDSTSavings() != 0 &&
                        tr2.GetTo().GetDSTSavings() == 0 ||
                        tr1.GetTo().GetDSTSavings() == 0 &&
                        tr2.GetTo().GetDSTSavings() != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (tr1.GetTo().GetRawOffset() != tr2.GetTo().GetRawOffset() ||
                        tr1.GetTo().GetDSTSavings() != tr2.GetTo()
                        .GetDSTSavings())
                    {
                        return(false);
                    }
                }
                time = tr1.GetTime();
            }
            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 /// TimeZone API; calls through to wrapped time zone.
 /// </summary>
 ///
 public override int GetOffset(int era, int year, int month, int day, int dayOfWeek,
                               int millis)
 {
     return(zone.GetOffset(era, year, month, day, dayOfWeek, millis));
 }