diff options
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/Cargo.toml | 2 | ||||
| -rw-r--r-- | cli/src/main.rs | 29 |
2 files changed, 27 insertions, 4 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index fc0f7ddd..c811db2f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -23,7 +23,6 @@ doc = false typst = { path = ".." } typst-library = { path = "../library" } atty = "0.2" -chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } clap = { version = "4.2.4", features = ["derive", "env"] } codespan-reporting = "0.11" comemo = "0.3" @@ -37,6 +36,7 @@ open = "4.0.2" same-file = "1" siphasher = "0.3" tempfile = "3.5.0" +time = { version = "0.3.20", features = ["formatting", "local-offset", "macros"] } tracing = "0.1.37" tracing-error = "0.2" tracing-flame = "0.2.0" diff --git a/cli/src/main.rs b/cli/src/main.rs index 408fe2f2..f2fcec0c 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,6 +6,7 @@ use std::collections::HashMap; use std::fs::{self, File}; use std::hash::Hash; use std::io::{self, Write}; +use std::ops::Add; use std::path::{Path, PathBuf}; use std::process::ExitCode; @@ -21,8 +22,10 @@ use once_cell::unsync::OnceCell; use same_file::{is_same_file, Handle}; use siphasher::sip128::{Hasher128, SipHasher13}; use termcolor::{ColorChoice, StandardStream, WriteColor}; +use time::macros::format_description; +use time::Duration; use typst::diag::{FileError, FileResult, SourceError, StrResult}; -use typst::eval::Library; +use typst::eval::{Datetime, Library}; use typst::font::{Font, FontBook, FontInfo, FontVariant}; use typst::syntax::{Source, SourceId}; use typst::util::{Buffer, PathExt}; @@ -291,8 +294,8 @@ fn status(command: &CompileSettings, status: Status) -> io::Result<()> { let esc = 27 as char; let input = command.input.display(); let output = command.output.display(); - let time = chrono::offset::Local::now(); - let timestamp = time.format("%H:%M:%S"); + let time = time::OffsetDateTime::now_local().unwrap(); + let timestamp = time.format(format_description!("[hour]:[minute]:[second]")).unwrap(); let message = status.message(); let color = status.color(); @@ -427,6 +430,7 @@ struct SystemWorld { hashes: RefCell<HashMap<PathBuf, FileResult<PathHash>>>, paths: RefCell<HashMap<PathHash, PathSlot>>, sources: FrozenVec<Box<Source>>, + current_date: Cell<Option<Datetime>>, main: SourceId, } @@ -457,6 +461,7 @@ impl SystemWorld { hashes: RefCell::default(), paths: RefCell::default(), sources: FrozenVec::new(), + current_date: Cell::new(None), main: SourceId::detached(), } } @@ -511,6 +516,23 @@ impl World for SystemWorld { .get_or_init(|| read(path).map(Buffer::from)) .clone() } + + fn today(&self, offset: Option<i64>) -> Option<Datetime> { + if self.current_date.get().is_none() { + let datetime = match offset { + None => time::OffsetDateTime::now_local().ok()?, + Some(o) => time::OffsetDateTime::now_utc().add(Duration::hours(o)), + }; + + self.current_date.set(Some(Datetime::from_ymd( + datetime.year(), + datetime.month().try_into().ok()?, + datetime.day(), + )?)) + } + + self.current_date.get() + } } impl SystemWorld { @@ -572,6 +594,7 @@ impl SystemWorld { self.sources.as_mut().clear(); self.hashes.borrow_mut().clear(); self.paths.borrow_mut().clear(); + self.current_date.set(None); } } |
