ICU-6577 Truncate time zone trunsition data out of signed in32 seconds range.

X-SVN-Rev: 24753
This commit is contained in:
Yoshito Umaoka 2008-10-08 14:30:17 +00:00
parent a57e83d1fb
commit 6c9239aa08
2 changed files with 28 additions and 2 deletions

View file

@ -1,7 +1,7 @@
/*
**********************************************************************
* Copyright (c) 2003-2007, International Business Machines
* Copyright (c) 2003-2008, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* Author: Alan Liu
@ -59,6 +59,7 @@ using namespace std;
const int64_t SECS_PER_YEAR = 31536000; // 365 days
const int64_t SECS_PER_LEAP_YEAR = 31622400; // 366 days
const int64_t LOWEST_TIME32 = (int64_t)((int32_t)0x80000000);
const int64_t HIGHEST_TIME32 = (int64_t)((int32_t)0x7fffffff);
bool isLeap(int32_t y) {
return (y%4 == 0) && ((y%100 != 0) || (y%400 == 0)); // Gregorian
@ -368,6 +369,11 @@ void readzoneinfo(ifstream& file, ZoneInfo& info, bool is64bitData=false) {
// Preserve the latest transition before the 32bit minimum time
minidx = i;
}
} else if (transitionTimes[i] > HIGHEST_TIME32) {
// Skipping the rest of the transition data. We cannot put such
// transitions into zoneinfo.res, because data is limited to singed
// 32bit int by the ICU resource bundle.
break;
} else {
info.transitions.push_back(Transition(transitionTimes[i], transitionTypes[i]));
}

View file

@ -2356,9 +2356,29 @@ wp = ecpyalloc(_("no POSIX environment variable for zone"));
* we may see unexpected offset shift at the
* begining of the year when the final rule takes
* effect. */
/* ICU currently can support signed int32 transition
* times. Thus, the transitions in year 2038 may be
* truncated. At this moment (tzdata2008g), only
* Rule Brazil is impacted by this limitation, because
* the final set of rules are starting in 2038. Although
* this code put the first couple of transitions populated
* by the final rules, they will be dropped off when
* collecting transition times. So, we need to keep
* the start year of the final rule in 2038, not 2039.
* Fortunately, the Brazil rules in 2038 and beyond use
* the same base offset/dst saving amount. Thus, even
* we skip the first couple of transitions, the final
* rule set for 2038 works properly. So for now,
* we do not increment the final rule start year only when
* it falls into year 2038. We need to revisit this code
* in future to fix the root cause of this problem (ICU
* resource type limitation - signed int32).
* Oct 7, 2008 - Yoshito */
int finalStartYear = (year == 2038) ? year : year + 1;
emit_icu_zone(icuFile,
zpfirst->z_name, zp->z_gmtoff,
rp, finalRuleIndex, year + 1);
rp, finalRuleIndex, finalStartYear);
/* only emit this for the first year */
finalRule1 = NULL;
}