Change imports of com.google.android.apps.chrome.R to be for org.chromium.chrome...
[chromium-blink-merge.git] / chromeos / settings / timezone_settings_helper.cc
blob781f774d8b1f84d856c0caae492752409244f341
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.
5 #include "chromeos/settings/timezone_settings_helper.h"
7 #include "base/logging.h"
8 #include "chromeos/chromeos_export.h"
10 namespace chromeos {
11 namespace system {
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;
40 // May return NULL if we did not find a matching timezone in our list.
41 return known_timezone;
44 } // namespace system
45 } // namespace chromeos