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/bash.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/bash.rs')
| -rw-r--r-- | atuin-client/src/import/bash.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/atuin-client/src/import/bash.rs b/atuin-client/src/import/bash.rs index 25ede053..fe080a55 100644 --- a/atuin-client/src/import/bash.rs +++ b/atuin-client/src/import/bash.rs @@ -1,10 +1,10 @@ use std::{fs::File, io::Read, path::PathBuf, str}; use async_trait::async_trait; -use chrono::{DateTime, Duration, NaiveDateTime, Utc}; use directories::UserDirs; use eyre::{eyre, Result}; use itertools::Itertools; +use time::{Duration, OffsetDateTime}; use super::{get_histpath, unix_byte_lines, Importer, Loader}; use crate::history::History; @@ -55,7 +55,7 @@ impl Importer for Bash { _ => None, }) // if no known timestamps, use now as base - .unwrap_or((lines.len(), Utc::now())); + .unwrap_or((lines.len(), OffsetDateTime::now_utc())); // if no timestamp is recorded, then use this increment to set an arbitrary timestamp // to preserve ordering @@ -99,7 +99,7 @@ enum LineType<'a> { Empty, /// A timestamp line start with a '#', followed immediately by an integer /// that represents seconds since UNIX epoch. - Timestamp(DateTime<Utc>), + Timestamp(OffsetDateTime), /// Anything else. Command(&'a str), } @@ -119,10 +119,9 @@ impl<'a> From<&'a [u8]> for LineType<'a> { } } -fn try_parse_line_as_timestamp(line: &str) -> Option<DateTime<Utc>> { +fn try_parse_line_as_timestamp(line: &str) -> Option<OffsetDateTime> { let seconds = line.strip_prefix('#')?.parse().ok()?; - let time = NaiveDateTime::from_timestamp(seconds, 0); - Some(DateTime::from_utc(time, Utc)) + OffsetDateTime::from_unix_timestamp(seconds).ok() } #[cfg(test)] @@ -183,7 +182,7 @@ cd ../ ["git reset", "git clean -dxf", "cd ../"], ); assert_equal( - loader.buf.iter().map(|h| h.timestamp.timestamp()), + loader.buf.iter().map(|h| h.timestamp.unix_timestamp()), [1672918999, 1672919006, 1672919020], ) } |
