From cb33594c4c00ccb021b03576ffcd9c8deab3cee7 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sat, 2 Nov 2024 12:04:25 +0100 Subject: [PATCH] Fix clock API (#698) --- src/api/clock.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/clock.rs b/src/api/clock.rs index 6d7ba833..1f6333d4 100644 --- a/src/api/clock.rs +++ b/src/api/clock.rs @@ -1,5 +1,5 @@ use crate::api::fs; -use core::convert::TryInto; +use alloc::string::String; pub const DATE_TIME_ZONE: &str = "%Y-%m-%d %H:%M:%S %z"; pub const DATE_TIME: &str = "%Y-%m-%d %H:%M:%S"; @@ -11,8 +11,10 @@ pub const DATE_LEN: usize = 10; fn read_float(path: &str) -> f64 { if let Ok(bytes) = fs::read_to_bytes(path) { - if bytes.len() == 8 { - return f64::from_be_bytes(bytes[0..8].try_into().unwrap()); + if let Ok(s) = String::from_utf8(bytes) { + if let Ok(n) = s.parse() { + return n; + } } } 0.0