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 BAAA3916E for ; Thu, 24 Aug 2023 16:20:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 93939339B9 for ; Thu, 24 Aug 2023 16:20:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 24 Aug 2023 16:20:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5040F43C4A for ; Thu, 24 Aug 2023 16:11:01 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Thu, 24 Aug 2023 16:11:00 +0200 Message-Id: <20230824141100.3690333-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.011 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 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] 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: Thu, 24 Aug 2023 14:20:59 -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 --- proxmox-time/src/wasm.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/proxmox-time/src/wasm.rs b/proxmox-time/src/wasm.rs index 04cea7d..59c26e2 100644 --- a/proxmox-time/src/wasm.rs +++ b/proxmox-time/src/wasm.rs @@ -14,10 +14,19 @@ 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"))?; + let len = js_date.len(); + if len < 24 { + bail!("invalid rfc3339 string"); + } + + // replace .xxxZ with Z + js_date.replace_range((len - 5).., "Z"); + + Ok(js_date) } /// Convert Unix epoch into RFC3339 local time with TZ -- 2.30.2