Skip to content

Commit 64c3e4d

Browse files
pebenderdjc
authored andcommitted
Add feature gated defmt support.
1 parent 9f782cd commit 64c3e4d

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

chrono-tz-build/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ fn write_timezone_file(timezone_file: &mut File, table: &Table, uncased: bool) -
140140
)?;
141141
}
142142

143+
writeln!(
144+
timezone_file,
145+
"#[cfg_attr(feature = \"defmt\", derive(defmt::Format))]"
146+
)?;
143147
writeln!(
144148
timezone_file,
145149
r#"#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -208,6 +212,16 @@ impl FromStr for Tz {{
208212
f.write_str(self.name().as_ref())
209213
}}
210214
}}\n"
215+
)?;
216+
writeln!(
217+
timezone_file,
218+
r#"#[cfg(feature = "defmt")]
219+
impl defmt::Format for Tz {{
220+
fn format(&self, f: defmt::Formatter) {{
221+
defmt::write!(f, "{{:?}}", self.name());
222+
}}
223+
}}
224+
"#
211225
)?;
212226
writeln!(
213227
timezone_file,

chrono-tz/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ include = [
3232
[dependencies]
3333
arbitrary = { version = "1.2", optional = true, features = ["derive"] }
3434
chrono = { version = "0.4.25", default-features = false }
35+
defmt = { version = "1.0.1", optional = true }
3536
serde_core = { version = "1.0.220", optional = true, default-features = false }
3637
phf = { version = "0.13", default-features = false }
3738
uncased = { version = "0.9", optional = true, default-features = false }
3839

3940
[features]
4041
default = ["std"]
4142
std = []
43+
defmt = ["dep:defmt"]
4244
serde = ["dep:serde_core"]
4345
filter-by-regex = ["chrono-tz-build", "chrono-tz-build/filter-by-regex"]
4446
case-insensitive = ["dep:uncased", "chrono-tz-build", "chrono-tz-build/case-insensitive", "phf/uncased"]

chrono-tz/src/prebuilt/timezones.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,7 @@ static TIMEZONES: ::phf::Map<&'static str, Tz> =
19311931
("Asia/Harbin", Tz::Asia__Harbin),
19321932
],
19331933
};
1934+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
19341935
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
19351936
pub struct ParseError(());
19361937

@@ -2565,6 +2566,13 @@ impl Display for Tz {
25652566
}
25662567
}
25672568

2569+
#[cfg(feature = "defmt")]
2570+
impl defmt::Format for Tz {
2571+
fn format(&self, f: defmt::Formatter) {
2572+
defmt::write!(f, "{:?}", self.name());
2573+
}
2574+
}
2575+
25682576
impl TimeSpans for Tz {
25692577
fn timespans(&self) -> FixedTimespanSet {
25702578
const AFRICA__ABIDJAN: FixedTimespanSet = FixedTimespanSet {

chrono-tz/src/timezone_impl.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ impl Debug for FixedTimespan {
3232
}
3333
}
3434

35+
#[cfg(feature = "defmt")]
36+
impl defmt::Format for FixedTimespan {
37+
fn format(&self, f: defmt::Formatter) {
38+
defmt::write!(f, "{:?}", self.name);
39+
}
40+
}
41+
3542
#[derive(Copy, Clone, PartialEq, Eq)]
3643
pub struct TzOffset {
3744
tz: Tz,
@@ -118,6 +125,13 @@ impl Debug for TzOffset {
118125
}
119126
}
120127

128+
#[cfg(feature = "defmt")]
129+
impl defmt::Format for TzOffset {
130+
fn format(&self, f: defmt::Formatter) {
131+
defmt::write!(f, "{:?}", self.offset);
132+
}
133+
}
134+
121135
/// Represents the span of time that a given rule is valid for.
122136
/// Note that I have made the assumption that all ranges are
123137
/// left-inclusive and right-exclusive - that is to say,

0 commit comments

Comments
 (0)