fix time format

This commit is contained in:
Laila van Reenen 2025-05-05 16:33:56 +02:00
parent ed1d701d94
commit a5bca9058a
Signed by: LailaTheElf
GPG Key ID: 8A3EF0226518C12D
3 changed files with 7 additions and 4 deletions

2
Cargo.lock generated
View File

@ -351,7 +351,7 @@ dependencies = [
[[package]]
name = "mqttClock"
version = "1.2.1"
version = "1.3.0"
dependencies = [
"chrono",
"crossbeam",

View File

@ -1,6 +1,6 @@
[package]
name = "mqttClock"
version = "1.2.1"
version = "1.3.0"
edition = "2021"
[dependencies]

View File

@ -57,7 +57,9 @@ impl Clock {
let minute = self.last_minute;
let hour = self.last_hour;
if let (Some(second), Some(minute), Some(hour)) = (second, minute, hour) {
let payload = format!("{{\"second\":{second},\"minute\":{minute},\"hour\":{hour},\"time\":\"{hour}:{minute}:{second}\"}}");
let payload =
format!("{{\"second\":{},\"minute\":{},\"hour\":{},\"time\":\"{}:{:02}:{:02}\"}}",
second, minute, hour, hour, minute, second);
let message = MqttMessage {
topic: String::from("clock/time/time"),
@ -66,7 +68,8 @@ impl Clock {
qos: QoS::AtMostOnce,
};
match self.tx.send(message) {
Err(n) => println!("ERROR: faild to send publish ({:?})", n),
Err(n) =>
println!("ERROR: faild to send publish ({:?})", n),
Ok(_) => {}
}
}