time icon indicating copy to clipboard operation
time copied to clipboard

Consider implementing `wasm-bindgen` conversion traits for various `time` structs

Open demhadais opened this issue 2 months ago • 1 comments

Hello! Just wanna start by saying I love the crate. I would like to improve the support for the structs in this crate by implementing FromWasmAbi and friends for structs in this crate, converting them to js_sys::Date. Maybe I could also implement support for converting structs in this crate to Temporal API objects behind some unstable feature flag and/or compilation options. This would enable users to do things like:

use wasm_bindgen::prelude::*;
use time::UtcDateTime;

#[wasm_bindgen]
struct MyStruct {
    pub time: UtcDateTime
}

I'd be happy to submit a PR with these changes if it sounds good!

demhadais avatar Oct 08 '25 15:10 demhadais

I haven't used wasm-bindgen in a very long time; the support only exists because others wanted it. What would this enable that is not currently possible? I don't know off-hand what that snippet is supposed to do.

Regarding potential implementation, feature flags are inherently stable; it's all or nothing. Additionally, given the name of the trait and its method, does this not necessarily want me to promise a certain ABI? That's a nonstarter if so, as I reserve the right to change the ABI of any struct in any manner, and in fact did so for most structs not that long ago.

jhpratt avatar Oct 19 '25 16:10 jhpratt