summaryrefslogtreecommitdiff
path: root/cli/src/main.rs
diff options
context:
space:
mode:
authorLaurenz Stampfl <47084093+LaurenzV@users.noreply.github.com>2023-05-24 12:14:43 +0200
committerGitHub <noreply@github.com>2023-05-24 12:14:43 +0200
commit6af94be34ad1cb657194c788c07681b28d87fbaf (patch)
tree143a74f56d5f216025f04af9582a1b9f7a9cce0d /cli/src/main.rs
parent6410ad2fe6fbdea88dcb7c7a17ff40a10d434c99 (diff)
Use chrono instead of time in the CLI (#1300)
Diffstat (limited to 'cli/src/main.rs')
-rw-r--r--cli/src/main.rs14
1 files changed, 6 insertions, 8 deletions
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()?,
)?))
}