| 2222 | } |
| 2223 | |
| 2224 | void |
| 2225 | time_zone::init_impl() |
| 2226 | { |
| 2227 | #if defined(ANDROID) || defined(__ANDROID__) |
| 2228 | return; |
| 2229 | #endif // defined(ANDROID) || defined(__ANDROID__) |
| 2230 | using namespace std; |
| 2231 | using namespace std::chrono; |
| 2232 | auto name = get_tz_dir() + ('/' + name_); |
| 2233 | std::ifstream inf(name); |
| 2234 | if (!inf.is_open()) |
| 2235 | throw std::runtime_error{"Unable to open " + name}; |
| 2236 | inf.exceptions(std::ios::failbit | std::ios::badbit); |
| 2237 | load_header(inf); |
| 2238 | auto v = load_version(inf); |
| 2239 | std::int32_t tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, |
| 2240 | tzh_timecnt, tzh_typecnt, tzh_charcnt; |
| 2241 | skip_reserve(inf); |
| 2242 | load_counts(inf, tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, |
| 2243 | tzh_timecnt, tzh_typecnt, tzh_charcnt); |
| 2244 | if (v == 0) |
| 2245 | { |
| 2246 | load_data<int32_t>(inf, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt); |
| 2247 | } |
| 2248 | else |
| 2249 | { |
| 2250 | #if !defined(NDEBUG) |
| 2251 | inf.ignore((4+1)*tzh_timecnt + 6*tzh_typecnt + tzh_charcnt + 8*tzh_leapcnt + |
| 2252 | tzh_ttisstdcnt + tzh_ttisgmtcnt); |
| 2253 | load_header(inf); |
| 2254 | auto v2 = load_version(inf); |
| 2255 | assert(v == v2); |
| 2256 | skip_reserve(inf); |
| 2257 | #else // defined(NDEBUG) |
| 2258 | inf.ignore((4+1)*tzh_timecnt + 6*tzh_typecnt + tzh_charcnt + 8*tzh_leapcnt + |
| 2259 | tzh_ttisstdcnt + tzh_ttisgmtcnt + (4+1+15)); |
| 2260 | #endif // defined(NDEBUG) |
| 2261 | load_counts(inf, tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, |
| 2262 | tzh_timecnt, tzh_typecnt, tzh_charcnt); |
| 2263 | load_data<int64_t>(inf, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt); |
| 2264 | } |
| 2265 | #if !MISSING_LEAP_SECONDS |
| 2266 | if (tzh_leapcnt > 0) |
| 2267 | { |
| 2268 | auto& leap_seconds = get_tzdb_list().front().leap_seconds; |
| 2269 | auto itr = leap_seconds.begin(); |
| 2270 | auto l = itr->date(); |
| 2271 | seconds leap_count{0}; |
| 2272 | for (auto t = std::upper_bound(transitions_.begin(), transitions_.end(), l, |
| 2273 | [](const sys_seconds& x, const transition& ct) |
| 2274 | { |
| 2275 | return x < ct.timepoint; |
| 2276 | }); |
| 2277 | t != transitions_.end(); ++t) |
| 2278 | { |
| 2279 | while (t->timepoint >= l) |
| 2280 | { |
| 2281 | ++leap_count; |
no test coverage detected