From 1770336c11ecec103c25d7956b42885398037585 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 9 Jan 2022 12:28:22 +0900 Subject: [PATCH] Make format_datetime() crate public --- plume-models/src/lib.rs | 28 ++++++++++++++++++++++++++++ plume-models/src/posts.rs | 30 +----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index fd93a601..546d5997 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -334,6 +334,7 @@ impl SmtpNewWithAddr for smtp::SmtpClient { #[macro_use] mod tests { use crate::{db_conn, migrations::IMPORTED_MIGRATIONS, Connection as Conn, CONFIG}; + use chrono::{naive::NaiveDateTime, Datelike, Timelike}; use diesel::r2d2::ConnectionManager; use plume_common::utils::random_hex; use std::env::temp_dir; @@ -366,6 +367,33 @@ mod tests { pool }; } + + #[cfg(feature = "postgres")] + pub(crate) fn format_datetime(dt: &NaiveDateTime) -> String { + format!( + "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}.{:06}Z", + dt.year(), + dt.month(), + dt.day(), + dt.hour(), + dt.minute(), + dt.second(), + dt.timestamp_subsec_micros() + ) + } + + #[cfg(feature = "sqlite")] + pub(crate) fn format_datetime(dt: &NaiveDateTime) -> String { + format!( + "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z", + dt.year(), + dt.month(), + dt.day(), + dt.hour(), + dt.minute(), + dt.second() + ) + } } pub mod admin; diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 391ede1f..65c98735 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -944,39 +944,11 @@ mod tests { use crate::inbox::{inbox, tests::fill_database, InboxResult}; use crate::mentions::{Mention, NewMention}; use crate::safe_string::SafeString; - use crate::tests::db; + use crate::tests::{db, format_datetime}; use assert_json_diff::assert_json_eq; - use chrono::{naive::NaiveDateTime, Datelike, Timelike}; use diesel::Connection; use serde_json::{json, to_value}; - #[cfg(feature = "postgres")] - fn format_datetime(dt: &NaiveDateTime) -> String { - format!( - "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}.{:06}Z", - dt.year(), - dt.month(), - dt.day(), - dt.hour(), - dt.minute(), - dt.second(), - dt.timestamp_subsec_micros() - ) - } - - #[cfg(feature = "sqlite")] - fn format_datetime(dt: &NaiveDateTime) -> String { - format!( - "{:04}-{:02}-{:02}T{:02}:{:02}:{:02}Z", - dt.year(), - dt.month(), - dt.day(), - dt.hour(), - dt.minute(), - dt.second() - ) - } - fn prepare_activity(conn: &DbConn) -> (Post, Mention, Vec, Vec, Vec) { let (posts, users, blogs) = fill_database(conn); let post = &posts[0];