Skip to content

Commit c497f87

Browse files
committed
fix time panic on wasm
1 parent d58f135 commit c497f87

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/app/result_export.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use super::*;
2+
#[cfg(not(target_arch = "wasm32"))]
23
use chrono::{SecondsFormat, Utc};
34
#[cfg(not(target_arch = "wasm32"))]
45
use egui_file_dialog::DialogState;
56
use serde::Serialize;
67
#[cfg(not(target_arch = "wasm32"))]
78
use std::path::PathBuf;
9+
#[cfg(target_arch = "wasm32")]
10+
use web_sys::js_sys::Date;
811

912
#[derive(Debug, Clone, Serialize)]
1013
pub(super) struct FitExportRecord {
@@ -244,11 +247,17 @@ impl CurveFitApp {
244247
}
245248
}
246249

250+
#[cfg(not(target_arch = "wasm32"))]
247251
fn now_utc_rfc3339_millis() -> String {
248252
chrono::DateTime::<Utc>::from(std::time::SystemTime::now())
249253
.to_rfc3339_opts(SecondsFormat::Millis, true)
250254
}
251255

256+
#[cfg(target_arch = "wasm32")]
257+
fn now_utc_rfc3339_millis() -> String {
258+
Date::new_0().to_iso_string().into()
259+
}
260+
252261
fn metric_quantization_decimal_places(metric_quantization: MetricQuantization) -> Option<u8> {
253262
match metric_quantization {
254263
MetricQuantization::Disabled => None,

0 commit comments

Comments
 (0)