Skip to content

Commit 2f115fe

Browse files
committed
Adjustments to preserve local record order in tzif
1 parent dbe95dc commit 2f115fe

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zoneinfo/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exclude.workspace = true
1111

1212
[dependencies]
1313
hashbrown = "0.15.2"
14+
indexmap = "2.9.0"
1415

1516
[dev-dependencies]
1617
tzif = { workspace = true }

zoneinfo/src/tzif.rs

+11-16
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
66
// TODO: Potentially add some serialization scheme?
77

8-
use alloc::{vec, vec::Vec};
9-
use hashbrown::HashSet;
8+
use alloc::vec::Vec;
9+
use indexmap::IndexSet;
1010

1111
use crate::ZoneInfoTransitionData;
1212

@@ -22,7 +22,11 @@ pub struct TzifBlockV2 {
2222

2323
impl TzifBlockV2 {
2424
pub fn from_transition_data(data: &ZoneInfoTransitionData) -> Self {
25-
let mut local_time_set = HashSet::new();
25+
let mut local_time_set = IndexSet::new();
26+
local_time_set.insert(LocalTimeRecord {
27+
offset: data.lmt.offset,
28+
is_dst: data.lmt.saving.as_secs() != 0,
29+
});
2630
let mut transition_times = Vec::default();
2731
let mut transition_types = Vec::default();
2832
for transition in &data.transitions {
@@ -39,19 +43,10 @@ impl TzifBlockV2 {
3943
}
4044
}
4145

42-
let first = LocalTimeRecord {
43-
offset: data.lmt.offset,
44-
is_dst: data.lmt.saving.as_secs() != 0,
45-
};
46-
47-
let mut local_time_types: Vec<LocalTimeRecord> = vec![first];
48-
local_time_types.extend_from_slice(
49-
local_time_set
50-
.iter()
51-
.cloned()
52-
.collect::<Vec<LocalTimeRecord>>()
53-
.as_slice(),
54-
);
46+
let local_time_types = local_time_set
47+
.iter()
48+
.cloned()
49+
.collect::<Vec<LocalTimeRecord>>();
5550

5651
Self {
5752
transition_times,

0 commit comments

Comments
 (0)