Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: src/i18n.cc

Issue 2813863002: Reland of [date] Add ICU backend for timezone info behind a flag (Closed)
Patch Set: Skip tests on noi18n Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/i18n.h ('k') | test/mjsunit/icu-date-lord-howe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // limitations under the License. 4 // limitations under the License.
5 5
6 #include "src/i18n.h" 6 #include "src/i18n.h"
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "src/api.h" 10 #include "src/api.h"
11 #include "src/factory.h" 11 #include "src/factory.h"
12 #include "src/isolate.h" 12 #include "src/isolate.h"
13 #include "src/objects-inl.h" 13 #include "src/objects-inl.h"
14 #include "src/string-case.h" 14 #include "src/string-case.h"
15 #include "unicode/brkiter.h" 15 #include "unicode/brkiter.h"
16 #include "unicode/bytestream.h"
16 #include "unicode/calendar.h" 17 #include "unicode/calendar.h"
17 #include "unicode/coll.h" 18 #include "unicode/coll.h"
18 #include "unicode/curramt.h" 19 #include "unicode/curramt.h"
19 #include "unicode/dcfmtsym.h" 20 #include "unicode/dcfmtsym.h"
20 #include "unicode/decimfmt.h" 21 #include "unicode/decimfmt.h"
21 #include "unicode/dtfmtsym.h" 22 #include "unicode/dtfmtsym.h"
22 #include "unicode/dtptngen.h" 23 #include "unicode/dtptngen.h"
23 #include "unicode/gregocal.h" 24 #include "unicode/gregocal.h"
24 #include "unicode/locid.h" 25 #include "unicode/locid.h"
25 #include "unicode/numfmt.h" 26 #include "unicode/numfmt.h"
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1206 }
1206 1207
1207 return LocaleConvertCase(s, isolate, true, ""); 1208 return LocaleConvertCase(s, isolate, true, "");
1208 } 1209 }
1209 1210
1210 MUST_USE_RESULT Object* ConvertCase(Handle<String> s, bool is_upper, 1211 MUST_USE_RESULT Object* ConvertCase(Handle<String> s, bool is_upper,
1211 Isolate* isolate) { 1212 Isolate* isolate) {
1212 return is_upper ? ConvertToUpper(s, isolate) : ConvertToLower(s, isolate); 1213 return is_upper ? ConvertToUpper(s, isolate) : ConvertToLower(s, isolate);
1213 } 1214 }
1214 1215
1216 ICUTimezoneCache::ICUTimezoneCache() : timezone_(nullptr) { Clear(); }
1217
1218 ICUTimezoneCache::~ICUTimezoneCache() { Clear(); }
1219
1220 const char* ICUTimezoneCache::LocalTimezone(double time_ms) {
1221 bool is_dst = DaylightSavingsOffset(time_ms) != 0;
1222 char* name = is_dst ? dst_timezone_name_ : timezone_name_;
1223 if (name[0] == '\0') {
1224 icu::UnicodeString result;
1225 GetTimeZone()->getDisplayName(is_dst, icu::TimeZone::LONG, result);
1226 result += '\0';
1227
1228 icu::CheckedArrayByteSink byte_sink(name, kMaxTimezoneChars);
1229 result.toUTF8(byte_sink);
1230 CHECK(!byte_sink.Overflowed());
1231 }
1232 return const_cast<const char*>(name);
1233 }
1234
1235 icu::TimeZone* ICUTimezoneCache::GetTimeZone() {
1236 if (timezone_ == nullptr) {
1237 timezone_ = icu::TimeZone::createDefault();
1238 }
1239 return timezone_;
1240 }
1241
1242 bool ICUTimezoneCache::GetOffsets(double time_ms, int32_t* raw_offset,
1243 int32_t* dst_offset) {
1244 UErrorCode status = U_ZERO_ERROR;
1245 GetTimeZone()->getOffset(time_ms, false, *raw_offset, *dst_offset, status);
1246 return U_SUCCESS(status);
1247 }
1248
1249 double ICUTimezoneCache::DaylightSavingsOffset(double time_ms) {
1250 int32_t raw_offset, dst_offset;
1251 if (!GetOffsets(time_ms, &raw_offset, &dst_offset)) return 0;
1252 return dst_offset;
1253 }
1254
1255 double ICUTimezoneCache::LocalTimeOffset() {
1256 int32_t raw_offset, dst_offset;
1257 if (!GetOffsets(icu::Calendar::getNow(), &raw_offset, &dst_offset)) return 0;
1258 return raw_offset;
1259 }
1260
1261 void ICUTimezoneCache::Clear() {
1262 delete timezone_;
1263 timezone_ = nullptr;
1264 timezone_name_[0] = '\0';
1265 dst_timezone_name_[0] = '\0';
1266 }
1267
1215 } // namespace internal 1268 } // namespace internal
1216 } // namespace v8 1269 } // namespace v8
OLDNEW
« no previous file with comments | « src/i18n.h ('k') | test/mjsunit/icu-date-lord-howe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698