Skip to content

Commit 711baee

Browse files
robertbastiandjc
authored andcommitted
chrono-tz-build: deduplicate links
1 parent 9bac8a1 commit 711baee

File tree

2 files changed

+38778
-73357
lines changed

2 files changed

+38778
-73357
lines changed

chrono-tz-build/src/lib.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ fn format_rest(rest: Vec<(i64, FixedTimespan)>) -> String {
4444
) in rest
4545
{
4646
ret.push_str(&format!(
47-
" ({start}, FixedTimespan {{ \
47+
" ({start}, FixedTimespan {{ \
4848
utc_offset: {utc_offset}, dst_offset: {dst_offset}, name: Some({name:?}) \
4949
}}),\n",
5050
));
5151
}
52-
ret.push_str(" ]");
52+
ret.push_str(" ]");
5353
ret
5454
}
5555

@@ -211,35 +211,51 @@ impl FromStr for Tz {{
211211
writeln!(
212212
timezone_file,
213213
"impl TimeSpans for Tz {{
214-
fn timespans(&self) -> FixedTimespanSet {{
215-
match *self {{"
214+
fn timespans(&self) -> FixedTimespanSet {{"
216215
)?;
217216
for zone in &zones {
218-
let timespans = table.timespans(zone).unwrap();
217+
if table.links.get(zone.as_str()).is_some() {
218+
continue;
219+
}
219220
let zone_name = convert_bad_chars(zone);
221+
let timespans = table.timespans(zone).unwrap();
220222
writeln!(
221223
timezone_file,
222-
" Tz::{zone} => {{
223-
const REST: &[(i64, FixedTimespan)] = {rest};
224-
FixedTimespanSet {{
225-
first: FixedTimespan {{
226-
utc_offset: {utc},
227-
dst_offset: {dst},
228-
name: Some({name:?}),
229-
}},
230-
rest: REST
231-
}}
232-
}},\n",
233-
zone = zone_name,
224+
" const {zone}: FixedTimespanSet = FixedTimespanSet {{
225+
first: FixedTimespan {{ utc_offset: {utc}, dst_offset: {dst}, name: Some({name:?}) }},
226+
rest: {rest},
227+
}};\n",
228+
zone = zone_name.to_uppercase(),
234229
rest = format_rest(timespans.rest),
235230
utc = timespans.first.utc_offset,
236231
dst = timespans.first.dst_offset,
237232
name = timespans.first.name,
238233
)?;
239234
}
235+
236+
write!(
237+
timezone_file,
238+
"
239+
match *self {{
240+
"
241+
)?;
242+
243+
for zone in &zones {
244+
let zone_name = convert_bad_chars(zone);
245+
let target_name = if let Some(target) = table.links.get(zone.as_str()) {
246+
convert_bad_chars(target)
247+
} else {
248+
zone_name.clone()
249+
};
250+
writeln!(
251+
timezone_file,
252+
" Tz::{zone_name} => {target_name},",
253+
target_name = target_name.to_uppercase(),
254+
)?;
255+
}
240256
write!(
241257
timezone_file,
242-
" }}
258+
" }}
243259
}}
244260
}}\n"
245261
)?;

0 commit comments

Comments
 (0)