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

Side by Side Diff: chromeos/settings/timezone_settings_helper.cc

Issue 1082323003: timezone match code - consider canonical id as well (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add const to for-loop variable Created 5 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
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/settings/timezone_settings_helper.h"
6
7 #include "base/logging.h"
8 #include "chromeos/chromeos_export.h"
9
10 namespace chromeos {
11 namespace system {
12
13 CHROMEOS_EXPORT const icu::TimeZone* GetKnownTimezoneOrNull(
14 const icu::TimeZone& timezone,
15 const std::vector<icu::TimeZone*>& timezone_list) {
16 const icu::TimeZone* known_timezone = NULL;
17 icu::UnicodeString id, canonical_id;
18 timezone.getID(id);
19 UErrorCode status = U_ZERO_ERROR;
20 icu::TimeZone::getCanonicalID(id, canonical_id, status);
21 DCHECK(U_SUCCESS(status));
22 for (const auto* entry : timezone_list) {
23 if (*entry == timezone)
24 return entry;
25 // Compare the canonical IDs as well.
26 // For instance, Asia/Ulan_Bator -> Asia/Ulaanbaatar or
27 // Canada/Pacific -> America/Vancouver
28 icu::UnicodeString entry_id, entry_canonical_id;
29 entry->getID(entry_id);
30 icu::TimeZone::getCanonicalID(entry_id, entry_canonical_id, status);
31 DCHECK(U_SUCCESS(status));
32 if (entry_canonical_id == canonical_id)
33 return entry;
34 // Last resort: If no match is found, the last timezone in the list
35 // with matching rules will be returned.
36 if (entry->hasSameRules(timezone))
37 known_timezone = entry;
38 }
39
40 // May return NULL if we did not find a matching timezone in our list.
41 return known_timezone;
42 }
43
44 } // namespace system
45 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698