I'm trying to create a filesystem API that under the hood uses std::{fs, path, env}. Futurely, for browser support, it'll use IndexedDB for special app: and app-storage: URLs.
I've to provide a way to get the creation_date() and modification_date() of my own File object:
I see that std::fs::Metadata (Metadata in std::fs - Rust) provides created and modified fields, but they return SystemTime. Can SystemTime be constructed when using IndexedDB (no plans yet) instead of std::{fs, env, path} and instead of Metadata? Is there a way to convert SystemTime to a zoned-date-time date?
The datetime crate provides ZonedDateTime. How would I translate a SystemTime into that?
If you compile to wasm32-unknown-unknown, the standard library assumes nothing about the system it runs on.
On WebAssembly, the SystemTime::now() constructor looks like this:
However, if you have some other means of knowing the current time (i.e. Date.now() from JavaScript), you can use SystemTime::EPOCH and SystemTime::checked_add() to create your timestamp using math.
I'd suggest creating your own version of std::fs::Metadata with the relevant fields. That way you can construct it yourself and the timestamps aren't required to come from the OS.