mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-15 03:38:07 +00:00
Can create text posts
This commit is contained in:
src
api_data
controllers
helpers
utils
@ -4,6 +4,8 @@
|
||||
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use chrono::{TimeZone, Utc};
|
||||
|
||||
/// Get the current time since epoch
|
||||
///
|
||||
/// ```
|
||||
@ -13,4 +15,23 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
||||
/// ```
|
||||
pub fn time() -> u64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()
|
||||
}
|
||||
|
||||
|
||||
/// Get Mysql formatted date at specific time
|
||||
///
|
||||
/// ```
|
||||
/// use comunic_server::utils::date_utils::time_to_mysql_date;
|
||||
///
|
||||
/// assert_eq!(time_to_mysql_date(1594140466), "2020-07-07 16:47:46");
|
||||
/// ```
|
||||
pub fn time_to_mysql_date(time: u64) -> String {
|
||||
let utc = Utc.timestamp(time as i64, 0);
|
||||
let str = utc.to_rfc3339();
|
||||
(&str[..19]).replace("T", " ")
|
||||
}
|
||||
|
||||
/// Get current Mysql formatted date
|
||||
pub fn mysql_date() -> String {
|
||||
time_to_mysql_date(time())
|
||||
}
|
@ -35,4 +35,19 @@ pub fn remove_html_nodes(input: &str) -> String {
|
||||
/// ```
|
||||
pub fn check_url(url: &str) -> bool {
|
||||
Uri::from_str(url).is_ok()
|
||||
}
|
||||
|
||||
/// Check a string before its insertion
|
||||
///
|
||||
/// Legacy function that might be completed / replaced in the future
|
||||
///
|
||||
/// ```
|
||||
/// use comunic_server::utils::string_utils::check_string_before_insert;
|
||||
///
|
||||
/// assert_eq!(check_string_before_insert("s"), false);
|
||||
/// assert_eq!(check_string_before_insert(" s"), false);
|
||||
/// assert_eq!(check_string_before_insert("Hello world"), true);
|
||||
/// ```
|
||||
pub fn check_string_before_insert(s: &str) -> bool {
|
||||
s.trim().len() > 3
|
||||
}
|
Reference in New Issue
Block a user