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

Side by Side Diff: src/i18n.cc

Issue 2724373002: [date] Add ICU backend for timezone info behind a flag (Closed)
Patch Set: Convert to UTF8 rather than check-failing Created 3 years, 9 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') | no next file » | 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 "unicode/brkiter.h" 14 #include "unicode/brkiter.h"
15 #include "unicode/bytestream.h"
15 #include "unicode/calendar.h" 16 #include "unicode/calendar.h"
16 #include "unicode/coll.h" 17 #include "unicode/coll.h"
17 #include "unicode/curramt.h" 18 #include "unicode/curramt.h"
18 #include "unicode/dcfmtsym.h" 19 #include "unicode/dcfmtsym.h"
19 #include "unicode/decimfmt.h" 20 #include "unicode/decimfmt.h"
20 #include "unicode/dtfmtsym.h" 21 #include "unicode/dtfmtsym.h"
21 #include "unicode/dtptngen.h" 22 #include "unicode/dtptngen.h"
22 #include "unicode/gregocal.h" 23 #include "unicode/gregocal.h"
23 #include "unicode/locid.h" 24 #include "unicode/locid.h"
24 #include "unicode/numfmt.h" 25 #include "unicode/numfmt.h"
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0)); 903 return reinterpret_cast<icu::BreakIterator*>(obj->GetInternalField(0));
903 } 904 }
904 905
905 void V8BreakIterator::DeleteBreakIterator( 906 void V8BreakIterator::DeleteBreakIterator(
906 const v8::WeakCallbackInfo<void>& data) { 907 const v8::WeakCallbackInfo<void>& data) {
907 delete reinterpret_cast<icu::BreakIterator*>(data.GetInternalField(0)); 908 delete reinterpret_cast<icu::BreakIterator*>(data.GetInternalField(0));
908 delete reinterpret_cast<icu::UnicodeString*>(data.GetInternalField(1)); 909 delete reinterpret_cast<icu::UnicodeString*>(data.GetInternalField(1));
909 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter())); 910 GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter()));
910 } 911 }
911 912
913 ICUTimezoneCache::ICUTimezoneCache() : timezone_(nullptr) { Clear(); }
914
915 ICUTimezoneCache::~ICUTimezoneCache() { Clear(); }
916
917 const char* ICUTimezoneCache::LocalTimezone(double time_ms) {
918 bool is_dst = DaylightSavingsOffset(time_ms) != 0;
919 char* name = is_dst ? dst_timezone_name_ : timezone_name_;
920 if (name[0] == '\0') {
921 icu::UnicodeString result;
922 GetTimeZone()->getDisplayName(is_dst, icu::TimeZone::LONG, result);
923 result += '\0';
924
925 icu::CheckedArrayByteSink byte_sink(name, kMaxTimezoneChars);
ulan 2017/03/17 11:00:05 CHECK(!byte_sink.Overflowed());
Dan Ehrenberg 2017/04/06 15:35:21 Check has been added.
926 result.toUTF8(byte_sink);
927 }
928 return const_cast<const char*>(name);
929 }
930
931 icu::TimeZone* ICUTimezoneCache::GetTimeZone() {
932 if (timezone_ == nullptr) {
933 timezone_ = icu::TimeZone::createDefault();
934 }
935 return timezone_;
936 }
937
938 bool ICUTimezoneCache::GetOffsets(double time_ms, int32_t* raw_offset,
939 int32_t* dst_offset) {
940 UErrorCode status = U_ZERO_ERROR;
941 GetTimeZone()->getOffset(time_ms, false, *raw_offset, *dst_offset, status);
942 return U_SUCCESS(status);
943 }
944
945 double ICUTimezoneCache::DaylightSavingsOffset(double time_ms) {
946 int32_t raw_offset, dst_offset;
947 if (!GetOffsets(time_ms, &raw_offset, &dst_offset)) return 0;
948 return dst_offset;
949 }
950
951 double ICUTimezoneCache::LocalTimeOffset() {
952 int32_t raw_offset, dst_offset;
953 if (!GetOffsets(icu::Calendar::getNow(), &raw_offset, &dst_offset)) return 0;
954 return raw_offset;
955 }
956
957 void ICUTimezoneCache::Clear() {
958 delete timezone_;
959 timezone_ = nullptr;
960 timezone_name_[0] = '\0';
961 dst_timezone_name_[0] = '\0';
962 }
963
912 } // namespace internal 964 } // namespace internal
913 } // namespace v8 965 } // namespace v8
OLDNEW
« no previous file with comments | « src/i18n.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698