aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-common/src')
-rw-r--r--atuin-common/src/api.rs11
-rw-r--r--atuin-common/src/record.rs2
-rw-r--r--atuin-common/src/utils.rs44
3 files changed, 27 insertions, 30 deletions
diff --git a/atuin-common/src/api.rs b/atuin-common/src/api.rs
index 5622bd82..ddcc0b09 100644
--- a/atuin-common/src/api.rs
+++ b/atuin-common/src/api.rs
@@ -1,6 +1,6 @@
-use chrono::Utc;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
+use time::OffsetDateTime;
#[derive(Debug, Serialize, Deserialize)]
pub struct UserResponse {
@@ -36,7 +36,8 @@ pub struct LoginResponse {
#[derive(Debug, Serialize, Deserialize)]
pub struct AddHistoryRequest {
pub id: String,
- pub timestamp: chrono::DateTime<Utc>,
+ #[serde(with = "time::serde::rfc3339")]
+ pub timestamp: OffsetDateTime,
pub data: String,
pub hostname: String,
}
@@ -48,8 +49,10 @@ pub struct CountResponse {
#[derive(Debug, Serialize, Deserialize)]
pub struct SyncHistoryRequest {
- pub sync_ts: chrono::DateTime<chrono::FixedOffset>,
- pub history_ts: chrono::DateTime<chrono::FixedOffset>,
+ #[serde(with = "time::serde::rfc3339")]
+ pub sync_ts: OffsetDateTime,
+ #[serde(with = "time::serde::rfc3339")]
+ pub history_ts: OffsetDateTime,
pub host: String,
}
diff --git a/atuin-common/src/record.rs b/atuin-common/src/record.rs
index b00c03c4..cba0917a 100644
--- a/atuin-common/src/record.rs
+++ b/atuin-common/src/record.rs
@@ -42,7 +42,7 @@ pub struct Record<Data> {
pub parent: Option<RecordId>,
/// The creation time in nanoseconds since unix epoch
- #[builder(default = chrono::Utc::now().timestamp_nanos() as u64)]
+ #[builder(default = time::OffsetDateTime::now_utc().unix_timestamp_nanos() as u64)]
pub timestamp: u64,
/// The version the data in the entry conforms to
diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs
index ed98e275..7cf4e9de 100644
--- a/atuin-common/src/utils.rs
+++ b/atuin-common/src/utils.rs
@@ -1,7 +1,6 @@
use std::env;
use std::path::PathBuf;
-use chrono::{Months, NaiveDate};
use rand::RngCore;
use uuid::Uuid;
@@ -37,7 +36,10 @@ const fn encode_unix_timestamp_millis(millis: u64, random_bytes: &[u8; 10]) -> U
pub fn uuid_v7() -> Uuid {
let bytes = random_bytes();
- let now: u64 = chrono::Utc::now().timestamp_millis() as u64;
+ let now: u64 = u64::try_from(
+ time::OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000,
+ )
+ .expect("Either you're in the past (1970) - or your in the far future (2554). Good for you");
encode_unix_timestamp_millis(now, &bytes)
}
@@ -111,18 +113,10 @@ pub fn get_current_dir() -> String {
}
}
-pub fn get_days_from_month(year: i32, month: u32) -> i64 {
- let Some(start) = NaiveDate::from_ymd_opt(year, month, 1) else {
- return 30;
- };
- let Some(end) = start.checked_add_months(Months::new(1)) else {
- return 30;
- };
- end.signed_duration_since(start).num_days()
-}
-
#[cfg(test)]
mod tests {
+ use time::Month;
+
use super::*;
use std::env;
@@ -170,21 +164,21 @@ mod tests {
#[test]
fn days_from_month() {
- assert_eq!(get_days_from_month(2023, 1), 31);
- assert_eq!(get_days_from_month(2023, 2), 28);
- assert_eq!(get_days_from_month(2023, 3), 31);
- assert_eq!(get_days_from_month(2023, 4), 30);
- assert_eq!(get_days_from_month(2023, 5), 31);
- assert_eq!(get_days_from_month(2023, 6), 30);
- assert_eq!(get_days_from_month(2023, 7), 31);
- assert_eq!(get_days_from_month(2023, 8), 31);
- assert_eq!(get_days_from_month(2023, 9), 30);
- assert_eq!(get_days_from_month(2023, 10), 31);
- assert_eq!(get_days_from_month(2023, 11), 30);
- assert_eq!(get_days_from_month(2023, 12), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::January), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::February), 28);
+ assert_eq!(time::util::days_in_year_month(2023, Month::March), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::April), 30);
+ assert_eq!(time::util::days_in_year_month(2023, Month::May), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::June), 30);
+ assert_eq!(time::util::days_in_year_month(2023, Month::July), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::August), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::September), 30);
+ assert_eq!(time::util::days_in_year_month(2023, Month::October), 31);
+ assert_eq!(time::util::days_in_year_month(2023, Month::November), 30);
+ assert_eq!(time::util::days_in_year_month(2023, Month::December), 31);
// leap years
- assert_eq!(get_days_from_month(2024, 2), 29);
+ assert_eq!(time::util::days_in_year_month(2024, Month::February), 29);
}
#[test]