From 151e2cfdfde2f166a06aef0f7ca4e28959831603 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 28 Aug 2023 15:29:32 +0200 Subject: [PATCH] time: make RFC3339 format in wasm conform to usual format on other targets we print the timestamp without fractional seconds ('.xxxZ'), so we should remove that too on wasm Signed-off-by: Dominik Csapak --- proxmox-time/src/wasm.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/proxmox-time/src/wasm.rs b/proxmox-time/src/wasm.rs index 04cea7d9..74e2060e 100644 --- a/proxmox-time/src/wasm.rs +++ b/proxmox-time/src/wasm.rs @@ -14,10 +14,18 @@ pub fn epoch_f64() -> f64 { pub fn epoch_to_rfc3339_utc(epoch: i64) -> Result { let js_date = js_sys::Date::new_0(); js_date.set_time((epoch as f64) * 1000.0); - js_date + let mut js_date = js_date .to_iso_string() .as_string() - .ok_or_else(|| format_err!("to_iso_string did not return a string")) + .ok_or_else(|| format_err!("to_iso_string did not return a string"))?; + + match js_date.len() { + len if len < 24 => bail!("invalid length {len} for rfc3339 string"), + len => { + js_date.replace_range((len - 5).., "Z"); // replace .xxxZ with Z + Ok(js_date) + } + } } /// Convert Unix epoch into RFC3339 local time with TZ