diff options
| author | Laurenz Stampfl <47084093+LaurenzV@users.noreply.github.com> | 2023-05-24 12:14:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-24 12:14:43 +0200 |
| commit | 6af94be34ad1cb657194c788c07681b28d87fbaf (patch) | |
| tree | 143a74f56d5f216025f04af9582a1b9f7a9cce0d /cli | |
| parent | 6410ad2fe6fbdea88dcb7c7a17ff40a10d434c99 (diff) | |
Use chrono instead of time in the CLI (#1300)
Diffstat (limited to 'cli')
| -rw-r--r-- | cli/Cargo.toml | 2 | ||||
| -rw-r--r-- | cli/src/main.rs | 14 |
2 files changed, 7 insertions, 9 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c811db2f..0a1eb7d1 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -23,6 +23,7 @@ doc = false typst = { path = ".." } typst-library = { path = "../library" } atty = "0.2" +chrono = { version = "0.4.24", default-features = false, features = ["clock", "std"] } clap = { version = "4.2.4", features = ["derive", "env"] } codespan-reporting = "0.11" comemo = "0.3" @@ -36,7 +37,6 @@ 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 b4f550e0..9b771163 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -6,11 +6,11 @@ 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; use atty::Stream; +use chrono::Datelike; use clap::Parser; use codespan_reporting::diagnostic::{Diagnostic, Label}; use codespan_reporting::term::{self, termcolor}; @@ -22,8 +22,6 @@ 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::doc::Document; use typst::eval::{Datetime, Library}; @@ -359,8 +357,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 = time::OffsetDateTime::now_local().unwrap(); - let timestamp = time.format(format_description!("[hour]:[minute]:[second]")).unwrap(); + let time = chrono::offset::Local::now(); + let timestamp = time.format("%H:%M:%S"); let message = status.message(); let color = status.color(); @@ -593,14 +591,14 @@ impl World for SystemWorld { 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)), + None => chrono::Local::now().naive_local(), + Some(o) => (chrono::Utc::now() + chrono::Duration::hours(o)).naive_utc(), }; self.current_date.set(Some(Datetime::from_ymd( datetime.year(), datetime.month().try_into().ok()?, - datetime.day(), + datetime.day().try_into().ok()?, )?)) } |
