From 27cf6d2af5ae1a4884164d3b0ca44fbbf4a8fab1 Mon Sep 17 00:00:00 2001 From: John Oxley Date: Fri, 15 May 2026 00:07:08 +0100 Subject: refactor: pull `fn into_utc` into atuin-server-database crate (#3487) The `fn into_utc` was defined in both `atuin-server-postgres` and `atuin-server-sqlite`, with tests being in the postgres crate. This pulls the function into the `atuin-server-database` crate along with the tests and references it from both crates. ## Checks - [X] I am happy for maintainers to push small adjustments to this PR, to speed up the review cycle - [X] I have checked that there are no existing pull requests for the same thing --- crates/atuin-server-database/src/lib.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'crates/atuin-server-database/src') diff --git a/crates/atuin-server-database/src/lib.rs b/crates/atuin-server-database/src/lib.rs index 9dd95eef..5437fc15 100644 --- a/crates/atuin-server-database/src/lib.rs +++ b/crates/atuin-server-database/src/lib.rs @@ -16,7 +16,7 @@ use self::{ use async_trait::async_trait; use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus}; use serde::{Deserialize, Serialize}; -use time::{Date, Duration, Month, OffsetDateTime, Time, UtcOffset}; +use time::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset}; use tracing::instrument; #[derive(Debug)] @@ -239,3 +239,30 @@ pub trait Database: Sized + Clone + Send + Sync + 'static { Ok(ret) } } + +pub fn into_utc(x: OffsetDateTime) -> PrimitiveDateTime { + let x = x.to_offset(UtcOffset::UTC); + PrimitiveDateTime::new(x.date(), x.time()) +} + +#[cfg(test)] +mod tests { + use time::macros::datetime; + + use crate::into_utc; + + #[test] + fn utc() { + let dt = datetime!(2023-09-26 15:11:02 +05:30); + assert_eq!(into_utc(dt), datetime!(2023-09-26 09:41:02)); + assert_eq!(into_utc(dt).assume_utc(), dt); + + let dt = datetime!(2023-09-26 15:11:02 -07:00); + assert_eq!(into_utc(dt), datetime!(2023-09-26 22:11:02)); + assert_eq!(into_utc(dt).assume_utc(), dt); + + let dt = datetime!(2023-09-26 15:11:02 +00:00); + assert_eq!(into_utc(dt), datetime!(2023-09-26 15:11:02)); + assert_eq!(into_utc(dt).assume_utc(), dt); + } +} -- cgit v1.3.1