mirror of
https://github.com/atuinsh/atuin.git
synced 2025-08-12 00:19:43 +02:00
fix sync timestamps (#1258)
* fix timestamp * add sync test * skip all sync tests
This commit is contained in:
@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use sqlx::Row;
|
||||
|
||||
use time::{OffsetDateTime, PrimitiveDateTime};
|
||||
use time::{OffsetDateTime, PrimitiveDateTime, UtcOffset};
|
||||
use tracing::instrument;
|
||||
use wrappers::{DbHistory, DbRecord, DbSession, DbUser};
|
||||
|
||||
@ -215,8 +215,8 @@ impl Database for Postgres {
|
||||
)
|
||||
.bind(user.id)
|
||||
.bind(host)
|
||||
.bind(created_after)
|
||||
.bind(since)
|
||||
.bind(into_utc(created_after))
|
||||
.bind(into_utc(since))
|
||||
.bind(page_size)
|
||||
.fetch(&self.pool)
|
||||
.map_ok(|DbHistory(h)| h)
|
||||
@ -450,3 +450,30 @@ impl Database for Postgres {
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use ::sqlx::{FromRow, Result};
|
||||
use atuin_common::record::{EncryptedData, Record};
|
||||
use atuin_server_database::models::{History, Session, User};
|
||||
use sqlx::{postgres::PgRow, Row};
|
||||
use time::PrimitiveDateTime;
|
||||
|
||||
pub struct DbUser(pub User);
|
||||
pub struct DbSession(pub Session);
|
||||
@ -36,9 +37,13 @@ impl<'a> ::sqlx::FromRow<'a, PgRow> for DbHistory {
|
||||
client_id: row.try_get("client_id")?,
|
||||
user_id: row.try_get("user_id")?,
|
||||
hostname: row.try_get("hostname")?,
|
||||
timestamp: row.try_get("timestamp")?,
|
||||
timestamp: row
|
||||
.try_get::<PrimitiveDateTime, _>("timestamp")?
|
||||
.assume_utc(),
|
||||
data: row.try_get("data")?,
|
||||
created_at: row.try_get("created_at")?,
|
||||
created_at: row
|
||||
.try_get::<PrimitiveDateTime, _>("created_at")?
|
||||
.assume_utc(),
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user