From f90c01f702f6a98b041f766b6a1d857bc1b9afef Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Mon, 11 Sep 2023 09:26:05 +0100 Subject: replace chrono with time (#806) * replace chrono with time * Fix test chrono usage --------- Co-authored-by: Ellie Huxtable --- atuin-client/src/import/bash.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'atuin-client/src/import/bash.rs') 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), + 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> { +fn try_parse_line_as_timestamp(line: &str) -> Option { 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], ) } -- cgit v1.3.1