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"
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
;
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
)
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
)
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
;
45 } // namespace chromeos