Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 26 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ version = "3.0.0-alpha.3-develop"
opt-level = 3

[dependencies]
anyhow = "1.0.79"
anyhow = "1.0.81"
argon2 = "0"
async-trait = "0"
axum = { version = "0", features = ["multipart"] }
Expand Down
7 changes: 3 additions & 4 deletions src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::missing_errors_doc)]

use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::DateTime;
use serde::{Deserialize, Serialize};
use sqlx::sqlite::{SqlitePoolOptions, SqliteQueryResult};
use sqlx::{query, query_as, SqlitePool};
Expand Down Expand Up @@ -61,11 +61,10 @@ pub fn convert_timestamp_to_datetime(timestamp: i64) -> String {
// The expected format in database is: 2022-11-04 09:53:57
// MySQL uses a DATETIME column and SQLite uses a TEXT column.

let naive_datetime = NaiveDateTime::from_timestamp_opt(timestamp, 0).expect("Overflow of i64 seconds, very future!");
let datetime_again: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive_datetime, Utc);
let datetime = DateTime::from_timestamp(timestamp, 0).expect("Overflow of i64 seconds, very future!");

// Format without timezone
datetime_again.format("%Y-%m-%d %H:%M:%S").to_string()
datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}

pub struct SqliteDatabaseV2_0_0 {
Expand Down
10 changes: 8 additions & 2 deletions src/utils/clock.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Duration, Utc};
use chrono::{DateTime, TimeDelta, Utc};

pub const DATETIME_FORMAT: &str = "%Y-%m-%d %H:%M:%S";

Expand All @@ -14,9 +14,15 @@ pub fn now() -> u64 {
}

/// Returns the datetime some seconds ago.
///
/// # Panics
///
/// The function panics if the number of seconds passed as a parameter
/// are more than `i64::MAX` / `1_000` or less than `-i64::MAX` / `1_000`.
#[must_use]
pub fn seconds_ago_utc(seconds: i64) -> DateTime<chrono::Utc> {
Utc::now() - Duration::seconds(seconds)
Utc::now()
- TimeDelta::try_seconds(seconds).expect("seconds should be more than i64::MAX / 1_000 or less than -i64::MAX / 1_000")
}

/// Returns the current time in database format.
Expand Down