Skip to content

Commit c82654f

Browse files
committed
Clean up timezone implementation and use workspace dependencies
1 parent ce89c31 commit c82654f

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ gantz_egui = { version = "0.1.0", path = "crates/gantz_egui" }
5353
gantz_std = { version = "0.1.0", path = "crates/gantz_std" }
5454
hex = "0.4"
5555
humantime = "2.3"
56+
js-sys = "0.3"
5657
log = { version = "0.4", features = ["serde"] }
5758
petgraph = { version = "0.8", features = ["serde-1"] }
5859
ron = "0.10"

crates/gantz_egui/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ gantz_core.workspace = true
2323
gantz_std.workspace = true
2424
hex.workspace = true
2525
humantime.workspace = true
26+
js-sys.workspace = true
2627
log.workspace = true
2728
petgraph.workspace = true
2829
serde.workspace = true
@@ -32,7 +33,7 @@ time.workspace = true
3233
tracing = { workspace = true, optional = true }
3334
tracing-subscriber = { workspace = true, optional = true }
3435
web-time.workspace = true
35-
js-sys = "0.3"
36+
3637

3738
[dev-dependencies]
3839
dyn-clone.workspace = true

crates/gantz_egui/src/widget.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A collection of useful widgets for gantz.
2-
use time::{OffsetDateTime, UtcOffset};
32
#[cfg(target_arch = "wasm32")]
43
use js_sys::Date;
4+
use time::{OffsetDateTime, UtcOffset};
55

66
pub use command_palette::CommandPalette;
77
pub use gantz::{Gantz, GantzState};
@@ -27,26 +27,24 @@ pub mod trace_view;
2727
pub(crate) fn to_local_datetime(datetime: OffsetDateTime) -> OffsetDateTime {
2828
#[cfg(not(target_arch = "wasm32"))]
2929
{
30-
// Native: use time crate's method
30+
// Native platforms: use time crate's built-in method
3131
UtcOffset::current_local_offset()
3232
.map(|offset| datetime.to_offset(offset))
3333
.unwrap_or(datetime)
3434
}
3535

3636
#[cfg(target_arch = "wasm32")]
3737
{
38-
// WASM: manually get offset from JavaScript
38+
// WASM: get timezone offset from JavaScript Date API
3939
use js_sys::Date;
4040

4141
let js_date = Date::new_0();
4242
let offset_minutes = js_date.get_timezone_offset();
43-
44-
// Convert minutes to seconds (offset is negative of what we want)
4543
let offset_seconds = -(offset_minutes as i32 * 60);
4644

4745
match UtcOffset::from_whole_seconds(offset_seconds) {
4846
Ok(offset) => datetime.to_offset(offset),
49-
Err(_) => datetime, // Fallback to UTC
47+
Err(_) => datetime,
5048
}
5149
}
5250
}

0 commit comments

Comments
 (0)