-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exemplar cities format (
VVV
) (#6018)
- Loading branch information
1 parent
9fc2b42
commit 78933a6
Showing
43 changed files
with
4,007 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use std::collections::BTreeMap; | ||
|
||
use icu::calendar::Date; | ||
use icu::datetime::{fieldsets, DateTimeFormatter}; | ||
use icu::locale::locale; | ||
use icu::timezone::Time; | ||
|
||
fn main() { | ||
let mapper = icu::timezone::TimeZoneIdMapper::new(); | ||
let offsets = icu::timezone::ZoneOffsetCalculator::new(); | ||
|
||
let prefs = locale!("en").into(); | ||
|
||
let offset_formatter = DateTimeFormatter::try_new(prefs, fieldsets::O::new()).unwrap(); | ||
let non_location_formatter = DateTimeFormatter::try_new(prefs, fieldsets::V::new()).unwrap(); | ||
let city_formatter = DateTimeFormatter::try_new(prefs, fieldsets::X::new()).unwrap(); | ||
|
||
let reference_date = (Date::try_new_iso(2025, 1, 1).unwrap(), Time::midnight()); | ||
|
||
let mut grouped_tzs = BTreeMap::<_, Vec<_>>::new(); | ||
|
||
for tz in mapper.iter_bcp47() { | ||
if tz.0 == "unk" || tz.starts_with("utc") || tz.0 == "gmt" { | ||
continue; | ||
} | ||
|
||
let offsets = offsets | ||
.compute_offsets_from_time_zone(tz, reference_date) | ||
.unwrap(); | ||
|
||
let tzi = tz | ||
.with_offset(Some(offsets.standard)) | ||
.at_time(reference_date); | ||
|
||
grouped_tzs | ||
.entry(non_location_formatter.format(&tzi).to_string()) | ||
.or_default() | ||
.push((offsets, tzi)); | ||
} | ||
|
||
let mut list = Vec::new(); | ||
|
||
for (non_location, zones) in grouped_tzs { | ||
for (offsets, tzi) in &zones { | ||
list.push(( | ||
-offsets.standard.to_seconds(), | ||
format!( | ||
"({}{})", | ||
offset_formatter.format(tzi), | ||
if let Some(daylight) = offsets.daylight { | ||
format!( | ||
"/{}", | ||
offset_formatter.format( | ||
&tzi.time_zone_id() | ||
.with_offset(Some(daylight)) | ||
.at_time(reference_date) | ||
) | ||
) | ||
} else { | ||
String::new() | ||
} | ||
), | ||
if zones.len() == 1 { | ||
non_location.clone() | ||
} else { | ||
format!("{non_location} - {}", city_formatter.format(tzi)) | ||
}, | ||
)); | ||
} | ||
} | ||
|
||
list.sort_by(|a, b| (a.0, &a.2).cmp(&(b.0, &b.2))); | ||
|
||
for (_, offset, non_location) in &list { | ||
println!( | ||
"{offset:0$} {non_location}", | ||
list.iter().map(|(_, l, ..)| l.len()).max().unwrap() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.