use chrono::prelude::*;
pub fn date(utc: bool) -> String {
let fmt = "%Y-%m-%d";
return {
if utc {
Utc::now().format(fmt).to_string()
} else {
Local::now().format(fmt).to_string()
}
};
}
pub fn to_timestamp(date: &str, unit: &str) -> i64 {
let fmt = "%Y-%m-%d %H:%M:%S";
let timestamp = NaiveDateTime::parse_from_str(&*format!("{} 00:00:00", date), fmt).unwrap();
let local = Local.timestamp(0, 0).offset().utc_minus_local() as i64;
match unit {
"ms" => {
timestamp.timestamp_millis() + local * 1000
}
_ => {
timestamp.timestamp() + local
}
}
}