diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-09-11 09:26:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-11 09:26:05 +0100 |
| commit | f90c01f702f6a98b041f766b6a1d857bc1b9afef (patch) | |
| tree | 04a4755bd632abdcf398d0ce903163ed60a5a212 /atuin-client/src/import/zsh.rs | |
| parent | Use `case` for Linux distro choice in `install.sh` (#1200) (diff) | |
| download | atuin-f90c01f702f6a98b041f766b6a1d857bc1b9afef.zip | |
replace chrono with time (#806)
* replace chrono with time
* Fix test chrono usage
---------
Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
Diffstat (limited to 'atuin-client/src/import/zsh.rs')
| -rw-r--r-- | atuin-client/src/import/zsh.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/atuin-client/src/import/zsh.rs b/atuin-client/src/import/zsh.rs index e98819e2..632caff9 100644 --- a/atuin-client/src/import/zsh.rs +++ b/atuin-client/src/import/zsh.rs @@ -4,9 +4,9 @@ use std::{fs::File, io::Read, path::PathBuf}; use async_trait::async_trait; -use chrono::{prelude::*, Utc}; use directories::UserDirs; use eyre::{eyre, Result}; +use time::OffsetDateTime; use super::{get_histpath, unix_byte_lines, Importer, Loader}; use crate::history::History; @@ -58,7 +58,7 @@ impl Importer for Zsh { } async fn load(self, h: &mut impl Loader) -> Result<()> { - let now = chrono::Utc::now(); + let now = OffsetDateTime::now_utc(); let mut line = String::new(); let mut counter = 0; @@ -79,7 +79,7 @@ impl Importer for Zsh { counter += 1; h.push(parse_extended(command, counter)).await?; } else { - let offset = chrono::Duration::seconds(counter); + let offset = time::Duration::seconds(counter); counter += 1; let imported = History::import() @@ -102,11 +102,10 @@ fn parse_extended(line: &str, counter: i64) -> History { let time = time .parse::<i64>() - .unwrap_or_else(|_| chrono::Utc::now().timestamp()); - - let offset = chrono::Duration::milliseconds(counter); - let time = Utc.timestamp(time, 0); - let time = time + offset; + .ok() + .and_then(|t| OffsetDateTime::from_unix_timestamp(t).ok()) + .unwrap_or_else(OffsetDateTime::now_utc) + + time::Duration::milliseconds(counter); // use nanos, because why the hell not? we won't display them. let duration = duration.parse::<i64>().map_or(-1, |t| t * 1_000_000_000); @@ -121,8 +120,6 @@ fn parse_extended(line: &str, counter: i64) -> History { #[cfg(test)] mod test { - use chrono::prelude::*; - use chrono::Utc; use itertools::assert_equal; use crate::import::tests::TestLoader; @@ -135,25 +132,37 @@ mod test { assert_eq!(parsed.command, "cargo install atuin"); assert_eq!(parsed.duration, 0); - assert_eq!(parsed.timestamp, Utc.timestamp(1_613_322_469, 0)); + assert_eq!( + parsed.timestamp, + OffsetDateTime::from_unix_timestamp(1_613_322_469).unwrap() + ); let parsed = parse_extended("1613322469:10;cargo install atuin;cargo update", 0); assert_eq!(parsed.command, "cargo install atuin;cargo update"); assert_eq!(parsed.duration, 10_000_000_000); - assert_eq!(parsed.timestamp, Utc.timestamp(1_613_322_469, 0)); + assert_eq!( + parsed.timestamp, + OffsetDateTime::from_unix_timestamp(1_613_322_469).unwrap() + ); let parsed = parse_extended("1613322469:10;cargo :b̷i̶t̴r̵o̴t̴ ̵i̷s̴ ̷r̶e̵a̸l̷", 0); assert_eq!(parsed.command, "cargo :b̷i̶t̴r̵o̴t̴ ̵i̷s̴ ̷r̶e̵a̸l̷"); assert_eq!(parsed.duration, 10_000_000_000); - assert_eq!(parsed.timestamp, Utc.timestamp(1_613_322_469, 0)); + assert_eq!( + parsed.timestamp, + OffsetDateTime::from_unix_timestamp(1_613_322_469).unwrap() + ); let parsed = parse_extended("1613322469:10;cargo install \\n atuin\n", 0); assert_eq!(parsed.command, "cargo install \\n atuin"); assert_eq!(parsed.duration, 10_000_000_000); - assert_eq!(parsed.timestamp, Utc.timestamp(1_613_322_469, 0)); + assert_eq!( + parsed.timestamp, + OffsetDateTime::from_unix_timestamp(1_613_322_469).unwrap() + ); } #[tokio::test] |
