aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-server-database
diff options
context:
space:
mode:
authorJohn Oxley <john.oxley@gmail.com>2026-05-15 00:07:08 +0100
committerGitHub <noreply@github.com>2026-05-14 23:07:08 +0000
commit27cf6d2af5ae1a4884164d3b0ca44fbbf4a8fab1 (patch)
tree9dd9d7b90b35d2eabaf754d83831fb15bd5164af /crates/atuin-server-database
parentchore: vouch for all existing contributors (#3486) (diff)
downloadatuin-27cf6d2af5ae1a4884164d3b0ca44fbbf4a8fab1.zip
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
Diffstat (limited to 'crates/atuin-server-database')
-rw-r--r--crates/atuin-server-database/src/lib.rs29
1 files changed, 28 insertions, 1 deletions
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);
+ }
+}