Skip to content

Commit

Permalink
fix: use reflexo::time::now to get time in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 29, 2024
1 parent b971d24 commit 6a4e2ba
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/reflexo-world/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<F: CompilerFeat> World for CompilerWorld<F> {
/// If this function returns `None`, Typst's `datetime` function will
/// return an error.
fn today(&self, offset: Option<i64>) -> Option<Datetime> {
let now = self.now.get_or_init(chrono::Local::now);
let now = self.now.get_or_init(|| reflexo::time::now().into());

let naive = match offset {
None => now.naive_local(),
Expand Down
2 changes: 2 additions & 0 deletions crates/reflexo/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ pub use instant::Duration;
pub use instant::Instant;
pub use instant::SystemTime as Time;

/// Returns the UTC+0 time.
#[cfg(any(feature = "system", feature = "web"))]
pub fn now() -> Time {
Time::now()
}

/// Returns a dummy time on environments that do not support time.
#[cfg(not(any(feature = "system", feature = "web")))]
pub fn now() -> Time {
Time::UNIX_EPOCH
Expand Down

0 comments on commit 6a4e2ba

Please sign in to comment.