diff options
author | Conrad Ludgate <conradludgate@gmail.com> | 2023-09-11 09:26:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-11 09:26:05 +0100 |
commit | f90c01f702f6a98b041f766b6a1d857bc1b9afef (patch) | |
tree | 04a4755bd632abdcf398d0ce903163ed60a5a212 /atuin-server | |
parent | 2342a3392349c0ae9d742e9da9833590e6567d08 (diff) |
replace chrono with time (#806)
* replace chrono with time
* Fix test chrono usage
---------
Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
Diffstat (limited to 'atuin-server')
-rw-r--r-- | atuin-server/Cargo.toml | 4 | ||||
-rw-r--r-- | atuin-server/src/handlers/history.rs | 27 |
2 files changed, 16 insertions, 15 deletions
diff --git a/atuin-server/Cargo.toml b/atuin-server/Cargo.toml index f1c44b4ca..1b9ad859d 100644 --- a/atuin-server/Cargo.toml +++ b/atuin-server/Cargo.toml @@ -3,6 +3,7 @@ name = "atuin-server" edition = "2018" description = "server library for atuin" +rust-version = { workspace = true } version = { workspace = true } authors = { workspace = true } license = { workspace = true } @@ -14,7 +15,7 @@ atuin-common = { path = "../atuin-common", version = "16.0.0" } atuin-server-database = { path = "../atuin-server-database", version = "16.0.0" } tracing = "0.1" -chrono = { workspace = true } +time = { workspace = true } eyre = { workspace = true } uuid = { workspace = true } config = { workspace = true } @@ -27,7 +28,6 @@ async-trait = { workspace = true } axum = "0.6.4" http = "0.2" fs-err = { workspace = true } -chronoutil = "0.2.3" tower = "0.4" tower-http = { version = "0.3", features = ["trace"] } reqwest = { workspace = true } diff --git a/atuin-server/src/handlers/history.rs b/atuin-server/src/handlers/history.rs index bb0aa321e..263d6cba9 100644 --- a/atuin-server/src/handlers/history.rs +++ b/atuin-server/src/handlers/history.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, convert::TryFrom}; use axum::{ extract::{Path, Query, State}, @@ -6,6 +6,7 @@ use axum::{ Json, }; use http::StatusCode; +use time::Month; use tracing::{debug, error, instrument}; use super::{ErrorResponse, ErrorResponseStatus, RespExt}; @@ -63,16 +64,10 @@ pub async fn list<DB: Database>( }; let history = db - .list_history( - &user, - req.sync_ts.naive_utc(), - req.history_ts.naive_utc(), - &req.host, - page_size, - ) + .list_history(&user, req.sync_ts, req.history_ts, &req.host, page_size) .await; - if req.sync_ts.timestamp_nanos() < 0 || req.history_ts.timestamp_nanos() < 0 { + if req.sync_ts.unix_timestamp_nanos() < 0 || req.history_ts.unix_timestamp_nanos() < 0 { error!("client asked for history from < epoch 0"); return Err( ErrorResponse::reply("asked for history from before epoch 0") @@ -139,7 +134,7 @@ pub async fn add<DB: Database>( client_id: h.id, user_id: user.id, hostname: h.hostname, - timestamp: h.timestamp.naive_utc(), + timestamp: h.timestamp, data: h.data, }) .collect(); @@ -182,11 +177,17 @@ pub async fn calendar<DB: Database>( let year = params.get("year").unwrap_or(&0); let month = params.get("month").unwrap_or(&1); + let month = Month::try_from(*month as u8).map_err(|e| ErrorResponseStatus { + error: ErrorResponse { + reason: e.to_string().into(), + }, + status: http::StatusCode::BAD_REQUEST, + })?; let db = &state.0.database; let focus = match focus { "year" => db - .calendar(&user, TimePeriod::YEAR, *year, *month) + .calendar(&user, TimePeriod::YEAR, *year, month) .await .map_err(|_| { ErrorResponse::reply("failed to query calendar") @@ -194,7 +195,7 @@ pub async fn calendar<DB: Database>( }), "month" => db - .calendar(&user, TimePeriod::MONTH, *year, *month) + .calendar(&user, TimePeriod::MONTH, *year, month) .await .map_err(|_| { ErrorResponse::reply("failed to query calendar") @@ -202,7 +203,7 @@ pub async fn calendar<DB: Database>( }), "day" => db - .calendar(&user, TimePeriod::DAY, *year, *month) + .calendar(&user, TimePeriod::DAY, *year, month) .await .map_err(|_| { ErrorResponse::reply("failed to query calendar") |