Skip to content

Commit

Permalink
Revert "check in list"
Browse files Browse the repository at this point in the history
This reverts commit 742d511.
  • Loading branch information
robertbastian committed Jan 21, 2025
1 parent 0af1f1d commit 2efea0f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 519 deletions.
118 changes: 46 additions & 72 deletions components/datetime/examples/timezone_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use std::io::{BufWriter, Write};
use std::collections::BTreeMap;

use icu::calendar::Date;
use icu::datetime::{fieldsets, DateTimeFormatter};
Expand All @@ -17,94 +17,68 @@ fn main() {

let offset_formatter = DateTimeFormatter::try_new(prefs, fieldsets::O::new()).unwrap();
let non_location_formatter = DateTimeFormatter::try_new(prefs, fieldsets::V::new()).unwrap();
let location_formatter = DateTimeFormatter::try_new(prefs, fieldsets::L::new()).unwrap();
let non_location_specific_formatter =
DateTimeFormatter::try_new(prefs, fieldsets::Z::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 list = Vec::new();
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)
.with_zone_variant(icu_timezone::ZoneVariant::Standard);
.at_time(reference_date);

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()
}
),
non_location_formatter.format(&tzi).to_string(),
non_location_specific_formatter.format(&tzi).to_string(),
location_formatter.format(&tzi).to_string(),
city_formatter.format(&tzi).to_string(),
tzi.time_zone_id().to_string(),
));
grouped_tzs
.entry(non_location_formatter.format(&tzi).to_string())
.or_default()
.push((offsets, tzi));
}

list.sort_by(|a, b| (a.0, &a.6).cmp(&(b.0, &b.6)));

let o_len = list.iter().map(|(_, o, ..)| o.len()).max().unwrap();
let v_len = list.iter().map(|(_, _, v, ..)| v.len()).max().unwrap();
let z_len = list.iter().map(|(_, _, _, z, ..)| z.len()).max().unwrap();
let l_len = list
.iter()
.map(|(_, _, _, _, l, ..)| l.len())
.max()
.unwrap();
let x_len = list
.iter()
.map(|(_, _, _, _, _, x, _)| x.len())
.max()
.unwrap();
let i_len = list
.iter()
.map(|(_, _, _, _, _, _, i)| i.len())
.max()
.unwrap();
let mut list = Vec::new();

let mut file = BufWriter::new(
std::fs::File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/tz_list.md")).unwrap(),
);
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))
},
));
}
}

writeln!(
&mut file,
"|{:o_len$}|{:v_len$}|{:z_len$}|{:l_len$}|{:x_len$}|{:i_len$}",
"OOOO", "vvvv", "zzzz (standard)", "VVVV", "VVV", "V"
)
.unwrap();
writeln!(
&mut file,
"|{:-<o_len$}|{:-<v_len$}|{:-<z_len$}|{:-<l_len$}|{:-<x_len$}|{:-<i_len$}",
"", "", "", "", "", ""
)
.unwrap();
list.sort_by(|a, b| (a.0, &a.2).cmp(&(b.0, &b.2)));

for (_, o, v, z, l, x, i) in &list {
writeln!(
&mut file,
"|{o:o_len$}|{v:v_len$}|{z:z_len$}|{l:l_len$}|{x:x_len$}|{i:i_len$}|",
)
.unwrap();
for (_, offset, non_location) in &list {
println!(
"{offset:0$} {non_location}",
list.iter().map(|(_, l, ..)| l.len()).max().unwrap()
);
}
}
Loading

0 comments on commit 2efea0f

Please sign in to comment.