diff options
| author | John Oxley <john.oxley@gmail.com> | 2026-05-15 00:07:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-14 23:07:08 +0000 |
| commit | 27cf6d2af5ae1a4884164d3b0ca44fbbf4a8fab1 (patch) | |
| tree | 9dd9d7b90b35d2eabaf754d83831fb15bd5164af /crates/atuin-server-postgres/src/lib.rs | |
| parent | chore: vouch for all existing contributors (#3486) (diff) | |
| download | atuin-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-postgres/src/lib.rs')
| -rw-r--r-- | crates/atuin-server-postgres/src/lib.rs | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/crates/atuin-server-postgres/src/lib.rs b/crates/atuin-server-postgres/src/lib.rs index eeb9da14..2e69c7f2 100644 --- a/crates/atuin-server-postgres/src/lib.rs +++ b/crates/atuin-server-postgres/src/lib.rs @@ -6,12 +6,12 @@ use rand::Rng; use async_trait::async_trait; use atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus}; use atuin_server_database::models::{History, NewHistory, NewSession, NewUser, Session, User}; -use atuin_server_database::{Database, DbError, DbResult, DbSettings}; +use atuin_server_database::{Database, DbError, DbResult, DbSettings, into_utc}; use futures_util::TryStreamExt; use sqlx::Row; use sqlx::postgres::PgPoolOptions; -use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset}; +use time::OffsetDateTime; use tracing::instrument; use uuid::Uuid; use wrappers::{DbHistory, DbRecord, DbSession, DbUser}; @@ -579,30 +579,3 @@ impl Database for Postgres { Ok(status) } } - -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); - } -} |
