1use chrono::format::DelayedFormat;
2use chrono::format::StrftimeItems;
3use chrono::prelude::*;
4use serde::de;
5use serde::{Deserialize, Deserializer};
6
7pub async fn get_send_time() -> String {
8 let fmt = "%Y-%m-%d %H:%M:%S";
9 let now: DateTime<Local> = Local::now();
10 let dft: DelayedFormat<StrftimeItems> = now.format(fmt);
11 let str_date: String = dft.to_string();
12 str_date
14}
15
16pub fn get_unix() -> i64 {
17 time::OffsetDateTime::now_utc().unix_timestamp()
18}
19
20pub fn get_unix_nano() -> i128 {
21 time::OffsetDateTime::now_utc().unix_timestamp_nanos()
22}
23
24pub fn default_perent() -> f32 {
25 0.0
26}
27
28pub fn de_float_from_str<'a, D>(deserializer: D) -> Result<f32, D::Error>
29where
30 D: Deserializer<'a>,
31{
32 let str_val = String::deserialize(deserializer)?;
33 if str_val == "".to_string() {
34 return Ok(0.0);
35 }
36 str_val.parse::<f32>().map_err(de::Error::custom)
37}