From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2F2829D40 for ; Mon, 28 Aug 2023 15:29:35 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 100411DCF2 for ; Mon, 28 Aug 2023 15:29:35 +0200 (CEST) Received: from bookworm-dev.localdomain (unknown [94.136.29.99]) by firstgate.proxmox.com (Proxmox) with ESMTP for ; Mon, 28 Aug 2023 15:29:33 +0200 (CEST) Received: by bookworm-dev.localdomain (Postfix, from userid 1000) id ABE6F6027B; Mon, 28 Aug 2023 15:29:32 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 28 Aug 2023 15:29:32 +0200 Message-Id: <20230828132932.123123-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.386 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox v2] time: make RFC3339 format in wasm conform to usual format X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Aug 2023 13:29:35 -0000 on other targets we print the timestamp without fractional seconds ('.xxxZ'), so we should remove that too on wasm Signed-off-by: Dominik Csapak --- changes from v1: * adapt thomas suggestions (thanks) to make code shorter and the error better it's currently not possible to run cargo test in wasm32-unknown-unknown so any test we write here cannot be executed (would have to be done with another crate like 'wasm-bindgen-test' which requires a browser environment to run the tests) 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 04cea7d..3f58b99 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 -- 2.39.2