From 8c9653dca91c91ae72e931da845c2e91c5590c48 Mon Sep 17 00:00:00 2001 From: Yoshito Umaoka Date: Fri, 10 May 2013 16:32:04 +0000 Subject: [PATCH] ICU-10154 Optimized time zone historical offset iteration. X-SVN-Rev: 33632 --- .../classes/core/src/com/ibm/icu/impl/OlsonTimeZone.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/OlsonTimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/OlsonTimeZone.java index 89238305908..774223b78c4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/OlsonTimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/OlsonTimeZone.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2005-2012, International Business Machines Corporation and * + * Copyright (C) 2005-2013, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -669,6 +669,11 @@ public class OlsonTimeZone extends BasicTimeZone { transitionRulesInitialized = false; } + // Maximum absolute offset in seconds = 1 day. + // getHistoricalOffset uses this constant as safety margin of + // quick zone transition checking. + private static final int MAX_OFFSET_SECONDS = 86400; // 60 * 60 * 24; + private void getHistoricalOffset(long date, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt, int[] offsets) { if (transitionCount != 0) { @@ -683,7 +688,7 @@ public class OlsonTimeZone extends BasicTimeZone { int transIdx; for (transIdx = transitionCount - 1; transIdx >= 0; transIdx--) { long transition = transitionTimes64[transIdx]; - if (local) { + if (local && (sec >= (transition - MAX_OFFSET_SECONDS))) { int offsetBefore = zoneOffsetAt(transIdx - 1); boolean dstBefore = dstOffsetAt(transIdx - 1) != 0; -- 2.49.0